mirror of
https://github.com/curl/curl.git
synced 2026-07-26 01:07:16 +03:00
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
This commit is contained in:
parent
38203f1585
commit
c45360d463
61 changed files with 213 additions and 273 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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++) {
|
||||
|
|
|
|||
|
|
@ -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 { */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue