summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarian Klymov <nekto1989@gmail.com>2018-06-02 23:52:56 +0300
committerDaniel Stenberg <daniel@haxx.se>2018-06-11 11:14:48 +0200
commitc45360d4633850839bb9c2d77dbf8a8285e9ad49 (patch)
tree20159c553a74ed98c2431fc8f2852067f79ac4e9 /src
parent38203f1585da53e07e54e37c7d5da4d72f509a2e (diff)
downloadcurl-c45360d4633850839bb9c2d77dbf8a8285e9ad49.tar.gz
cppcheck: fix warnings
- Get rid of variable that was generating false positive warning (unitialized) - Fix issues in tests - Reduce scope of several variables all over etc Closes #2631
Diffstat (limited to 'src')
-rw-r--r--src/tool_cb_dbg.c10
-rw-r--r--src/tool_cb_prg.c12
-rw-r--r--src/tool_formparse.c5
-rw-r--r--src/tool_getparam.c6
-rw-r--r--src/tool_libinfo.c2
-rw-r--r--src/tool_msgs.c2
-rw-r--r--src/tool_paramhlp.c10
-rw-r--r--src/tool_parsecfg.c8
-rw-r--r--src/tool_urlglob.c2
-rw-r--r--src/tool_writeout.c4
10 files changed, 28 insertions, 33 deletions
diff --git a/src/tool_cb_dbg.c b/src/tool_cb_dbg.c
index 16bfb4208..c2dd51b7c 100644
--- a/src/tool_cb_dbg.c
+++ b/src/tool_cb_dbg.c
@@ -50,15 +50,15 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
FILE *output = config->errors;
const char *text;
struct timeval tv;
- struct tm *now;
char timebuf[20];
time_t secs;
- static time_t epoch_offset;
- static int known_offset;
(void)handle; /* not used */
if(config->tracetime) {
+ struct tm *now;
+ static time_t epoch_offset;
+ static int known_offset;
tv = tvnow();
if(!known_offset) {
epoch_offset = time(NULL) - tv.tv_sec;
@@ -101,14 +101,14 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
static const char * const s_infotype[] = {
"*", "<", ">", "{", "}", "{", "}"
};
- size_t i;
- size_t st = 0;
static bool newl = FALSE;
static bool traced_data = FALSE;
switch(type) {
case CURLINFO_HEADER_OUT:
if(size > 0) {
+ size_t st = 0;
+ size_t i;
for(i = 0; i < size - 1; i++) {
if(data[i] == '\n') { /* LF */
if(!newl) {
diff --git a/src/tool_cb_prg.c b/src/tool_cb_prg.c
index 60a3804f9..3eb2c1255 100644
--- a/src/tool_cb_prg.c
+++ b/src/tool_cb_prg.c
@@ -113,12 +113,6 @@ int tool_progress_cb(void *clientp,
/* The original progress-bar source code was written for curl by Lars Aas,
and this new edition inherits some of his concepts. */
- char line[MAX_BARLENGTH + 1];
- char format[40];
- double frac;
- double percent;
- int barwidth;
- int num;
struct timeval now = tvnow();
struct ProgressData *bar = (struct ProgressData *)clientp;
curl_off_t total;
@@ -154,6 +148,12 @@ int tool_progress_cb(void *clientp,
bar->calls++;
if((total > 0) && (point != bar->prev)) {
+ char line[MAX_BARLENGTH + 1];
+ char format[40];
+ double frac;
+ double percent;
+ int barwidth;
+ int num;
if(point > total)
/* we have got more than the expected total! */
total = point;
diff --git a/src/tool_formparse.c b/src/tool_formparse.c
index 9fcf014b8..5d1ea9c53 100644
--- a/src/tool_formparse.c
+++ b/src/tool_formparse.c
@@ -123,13 +123,12 @@ static int read_field_headers(struct OperationConfig *config,
{
size_t hdrlen = 0;
size_t pos = 0;
- int c;
bool incomment = FALSE;
int lineno = 1;
char hdrbuf[999]; /* Max. header length + 1. */
for(;;) {
- c = getc(fp);
+ int c = getc(fp);
if(c == EOF || (!pos && !ISSPACE(c))) {
/* Strip and flush the current header. */
while(hdrlen && ISSPACE(hdrbuf[hdrlen - 1]))
@@ -563,7 +562,6 @@ int formparse(struct OperationConfig *config,
struct curl_slist *headers = NULL;
curl_mimepart *part = NULL;
CURLcode res;
- int sep = '\0';
/* Allocate the main mime structure if needed. */
if(!*mimepost) {
@@ -585,6 +583,7 @@ int formparse(struct OperationConfig *config,
/* Scan for the end of the name. */
contp = strchr(contents, '=');
if(contp) {
+ int sep = '\0';
if(contp > contents)
name = contents;
*contp++ = '\0';
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index 186168252..cc3fcf3a5 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -506,8 +506,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
*usedarg = FALSE; /* default is that we don't use the arg */
- if(('-' != flag[0]) ||
- (('-' == flag[0]) && ('-' == flag[1]))) {
+ if(('-' != flag[0]) || ('-' == flag[1])) {
/* this should be a long name */
const char *word = ('-' == flag[0]) ? flag + 2 : flag;
size_t fnam = strlen(word);
@@ -2155,7 +2154,6 @@ ParameterError parse_args(struct GlobalConfig *config, int argc,
orig_opt = argv[i];
if(stillflags && ('-' == argv[i][0])) {
- char *nextarg;
bool passarg;
char *flag = argv[i];
@@ -2164,7 +2162,7 @@ ParameterError parse_args(struct GlobalConfig *config, int argc,
following (URL) argument to start with -. */
stillflags = FALSE;
else {
- nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
+ char *nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
result = getparameter(flag, nextarg, &passarg, config, operation);
if(result == PARAM_NEXT_OPERATION) {
diff --git a/src/tool_libinfo.c b/src/tool_libinfo.c
index d2bf7fb93..583570988 100644
--- a/src/tool_libinfo.c
+++ b/src/tool_libinfo.c
@@ -76,7 +76,6 @@ CURLcode get_libcurl_info(void)
{ NULL, 0 }
};
- struct proto_name_pattern const *p;
const char *const *proto;
/* Pointer to libcurl's run-time version information */
@@ -88,6 +87,7 @@ CURLcode get_libcurl_info(void)
built_in_protos = 0;
if(curlinfo->protocols) {
for(proto = curlinfo->protocols; *proto; proto++) {
+ struct proto_name_pattern const *p;
for(p = possibly_built_in; p->proto_name; p++) {
if(curl_strequal(*proto, p->proto_name)) {
built_in_protos |= p->proto_pattern;
diff --git a/src/tool_msgs.c b/src/tool_msgs.c
index 91d62ec1e..9cce8063e 100644
--- a/src/tool_msgs.c
+++ b/src/tool_msgs.c
@@ -109,8 +109,8 @@ void warnf(struct GlobalConfig *config, const char *fmt, ...)
void helpf(FILE *errors, const char *fmt, ...)
{
- va_list ap;
if(fmt) {
+ va_list ap;
va_start(ap, fmt);
fputs("curl: ", errors); /* prefix it */
vfprintf(errors, fmt, ap);
diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c
index 7cddf51ce..894d4d414 100644
--- a/src/tool_paramhlp.c
+++ b/src/tool_paramhlp.c
@@ -58,14 +58,14 @@ struct getout *new_getout(struct OperationConfig *config)
ParameterError file2string(char **bufp, FILE *file)
{
- char buffer[256];
char *ptr;
char *string = NULL;
- size_t stringlen = 0;
- size_t buflen;
if(file) {
+ char buffer[256];
+ size_t stringlen = 0;
while(fgets(buffer, sizeof(buffer), file)) {
+ size_t buflen;
ptr = strchr(buffer, '\r');
if(ptr)
*ptr = '\0';
@@ -91,11 +91,11 @@ ParameterError file2memory(char **bufp, size_t *size, FILE *file)
{
char *newbuf;
char *buffer = NULL;
- size_t alloc = 512;
size_t nused = 0;
- size_t nread;
if(file) {
+ size_t nread;
+ size_t alloc = 512;
do {
if(!buffer || (alloc == nused)) {
/* size_t overflow detection for huge files */
diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c
index 540bdb18a..34b5d8b25 100644
--- a/src/tool_parsecfg.c
+++ b/src/tool_parsecfg.c
@@ -46,11 +46,9 @@ static char *my_get_line(FILE *fp);
/* return 0 on everything-is-fine, and non-zero otherwise */
int parseconfig(const char *filename, struct GlobalConfig *global)
{
- int res;
FILE *file;
char filebuffer[512];
bool usedarg = FALSE;
- char *home;
int rc = 0;
struct OperationConfig *operation = global->first;
@@ -58,8 +56,8 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
/* NULL or no file name attempts to load .curlrc from the homedir! */
#ifndef __AMIGA__
+ char *home = homedir(); /* portable homedir finder */
filename = CURLRC; /* sensible default */
- home = homedir(); /* portable homedir finder */
if(home) {
if(strlen(home) < (sizeof(filebuffer) - strlen(CURLRC))) {
snprintf(filebuffer, sizeof(filebuffer),
@@ -125,13 +123,13 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
char *option;
char *param;
int lineno = 0;
- bool alloced_param;
bool dashed_option;
while(NULL != (aline = my_get_line(file))) {
+ int res;
+ bool alloced_param = FALSE;
lineno++;
line = aline;
- alloced_param = FALSE;
/* line with # in the first non-blank column is a comment! */
while(*line && ISSPACE(*line))
diff --git a/src/tool_urlglob.c b/src/tool_urlglob.c
index 6fae23620..fc8c2f529 100644
--- a/src/tool_urlglob.c
+++ b/src/tool_urlglob.c
@@ -622,12 +622,12 @@ CURLcode glob_match_url(char **result, char *filename, URLGlob *glob)
while(*filename) {
if(*filename == '#' && ISDIGIT(filename[1])) {
- unsigned long i;
char *ptr = filename;
unsigned long num = strtoul(&filename[1], &filename, 10);
URLPattern *pat = NULL;
if(num < glob->size) {
+ unsigned long i;
num--; /* make it zero based */
/* find the correct glob entry */
for(i = 0; i<glob->size; i++) {
diff --git a/src/tool_writeout.c b/src/tool_writeout.c
index 5d92bd278..ffe47c633 100644
--- a/src/tool_writeout.c
+++ b/src/tool_writeout.c
@@ -122,9 +122,9 @@ void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo)
else {
/* this is meant as a variable to output */
char *end;
- char keepit;
- int i;
if('{' == ptr[1]) {
+ char keepit;
+ int i;
bool match = FALSE;
end = strchr(ptr, '}');
ptr += 2; /* pass the % and the { */