Bug Summary

File:libsofia-sip-ua/nta/sl_read_payload.c
Warning:line 58, column 16
Although the value stored to 'fname' is used in the enclosing expression, the value is never actually read from 'fname'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name sl_read_payload.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-11/lib/clang/11.0.1 -D HAVE_CONFIG_H -I . -I ../.. -I ../../libsofia-sip-ua/su/sofia-sip -I ./../ipt -I ../ipt -I ./../msg -I ../msg -I ./../sip -I ../sip -I ./../bnf -I ../bnf -I ./../sresolv -I ../sresolv -I ./../tport -I ../tport -I ./../url -I ../url -I ./../features -I ../features -I ./../su -I ../su -I ../../s2check -I ./../stun -I ../stun -D SU_DEBUG=0 -D PIC -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.0.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /drone/src/libsofia-sip-ua/nta -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-output=html -faddrsig -o /drone/src/scan-build/2022-06-23-181620-12-1 -x c sl_read_payload.c
1/*
2 * This file is part of the Sofia-SIP package
3 *
4 * Copyright (C) 2005 Nokia Corporation.
5 *
6 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25/**@ingroup sl_utils
26 * @CFILE sl_read_payload.c
27 *
28 * @brief Functions for reading SIP message payload from a file.
29 *
30 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
31 *
32 * @date Created: Thu Sep 5 00:44:34 2002 ppessi
33 */
34
35#include "config.h"
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <errno(*__errno_location ()).h>
41
42#include <sofia-sip/sip_header.h>
43
44#include <sofia-sip/sl_utils.h>
45
46/** Read payload from named file.
47 *
48 * The function sl_read_payload() reads the contents to a SIP payload
49 * structure from a the named file. If @a fname is NULL, the payload
50 * contents are read from standard input.
51 */
52sip_payload_t *sl_read_payload(su_home_t *home, char const *fname)
53{
54 FILE *f;
55 sip_payload_t *pl;
56
57 if (fname == NULL((void*)0) || strcmp(fname, "-") == 0)
58 f = stdinstdin, fname = "<stdin>";
Although the value stored to 'fname' is used in the enclosing expression, the value is never actually read from 'fname'
59 else
60 f = fopen(fname, "rb");
61
62 if (f == NULL((void*)0))
63 return NULL((void*)0);
64
65 pl = sl_fread_payload(home, f);
66 if (f != stdinstdin)
67 fclose(f);
68
69 return pl;
70}
71
72sip_payload_t *sl_fread_payload(su_home_t *home, FILE *f)
73{
74 sip_payload_t *pl;
75 size_t n;
76 char *buf;
77 char const *who;
78 size_t used, size;
79
80 if (f == NULL((void*)0)) {
81 errno(*__errno_location ()) = EINVAL22;
82 return NULL((void*)0);
83 }
84
85 pl = sip_payload_create(home, NULL((void*)0), 0);
86
87 if (pl == NULL((void*)0))
88 return NULL((void*)0);
89
90 /* Read block by block */
91 used = 0;
92 size = 4096;
93 buf = malloc(size);
94 who = "sl_fread_payload: malloc";
95
96 while (buf) {
97 n = fread(buf + used, 1, size - used, f);
98 used += n;
99 if (n < size - used) {
100 if (feof(f))
101 ;
102 else if (ferror(f)) {
103 free(buf); buf = NULL((void*)0);
104 who = "sl_fread_payload: fread";
105 }
106 break;
107 }
108 buf = realloc(buf, size = 2 * size);
109 if (buf == NULL((void*)0))
110 who = "sl_fread_payload: realloc";
111 }
112
113 if (buf == NULL((void*)0)) {
114 perror(who);
115 su_free(home, pl);
116 return NULL((void*)0);
117 }
118
119 if (used < size)
120 buf[used] = '\0';
121
122 pl->pl_common->h_data = pl->pl_data = buf;
123 pl->pl_common->h_len = pl->pl_len = used;
124
125 return pl;
126}