Skip to content

Commit

Permalink
Fixed errors reported by cppcheck (when it makes sense to change the …
Browse files Browse the repository at this point in the history
…code)
  • Loading branch information
fdupoux committed Aug 9, 2016
1 parent fffaec4 commit c6ba47f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/archwriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ int archwriter_write_buffer(carchwriter *ai, struct s_writebuf *wb)

assert(ai);
assert(wb);
if (wb->size <=0)

if (wb->size == 0)
{ errprintf("wb->size=%ld\n", (long)wb->size);
return -1;
}

if ((lres=write(ai->archfd, (char*)wb->data, (long)wb->size))!=(long)wb->size)
{
errprintf("write(size=%ld) returned %ld\n", (long)wb->size, (long)lres);
Expand Down
5 changes: 2 additions & 3 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,9 @@ int exec_command(char *command, int cmdbufsize, int *exitst, char *stdoutbuf, in

// read the remaining data in the pipes
if ((stdoutbuf!=NULL) && (outpos+1 < stdoutsize))
res=read(mystdout, stdoutbuf+outpos, stdoutsize-outpos-1);
read(mystdout, stdoutbuf+outpos, stdoutsize-outpos-1);
if ((stderrbuf!=NULL) && (errpos+1 < stderrsize))
res=read(mystderr, stderrbuf+errpos, stderrsize-errpos-1);
read(mystderr, stderrbuf+errpos, stderrsize-errpos-1);

msgprintf(MSG_VERB1, "command [%s] returned %d\n", command, WEXITSTATUS(status));
if (exitst)
Expand Down Expand Up @@ -616,4 +616,3 @@ int get_path_to_volume(char *newvolbuf, int bufsize, char *basepath, long curvol

return 0;
}

2 changes: 1 addition & 1 deletion src/fs_reiser4.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ int reiser4_getinfo(cdico *d, char *devname)
temp16=le16_to_cpu(sb.blocksize);
if (temp16!=4096)
{ ret=-5;
goto reiser4_get_specific_close;
errprintf("invalid reiser4 block-size: %ld, it should be 4096\n", (long)temp16);
goto reiser4_get_specific_close;
}
else
{ dico_add_u64(d, 0, FSYSHEADKEY_FSREISER4BLOCKSIZE, temp16);
Expand Down
8 changes: 6 additions & 2 deletions src/fsarchiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ char *valid_magic[]={FSA_MAGIC_MAIN, FSA_MAGIC_VOLH, FSA_MAGIC_VOLF,

void usage(char *progname, bool examples)
{
int lzo=false, lzma=false;
int lzo, lzma;

#ifdef OPTION_LZO_SUPPORT
lzo=true;
#else
lzo=false;
#endif // OPTION_LZO_SUPPORT
#ifdef OPTION_LZMA_SUPPORT
lzma=true;
#else
lzma=false;
#endif // OPTION_LZMA_SUPPORT

msgprintf(MSG_FORCE, "====> fsarchiver version %s (%s) - http://www.fsarchiver.org <====\n", FSA_VERSION, FSA_RELDATE);
Expand Down
2 changes: 1 addition & 1 deletion src/oper_restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int convert_argv_to_strdicos(cstrdico *dicoargv[], int argc, char *cmdargv[])
int extractar_listing_print_file(cextractar *exar, int objtype, char *relpath)
{
char strprogress[256];
u64 progress;
s64 progress;

memset(strprogress, 0, sizeof(strprogress));
if (exar->cost_global>0)
Expand Down
14 changes: 5 additions & 9 deletions src/oper_save.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ int createar_item_xattr(csavear *save, char *root, char *relpath, struct stat64
len=strlen(buffer+pos)+1;
attrsize=lgetxattr(fullpath, buffer+pos, NULL, 0);
msgprintf(MSG_VERB2, " xattr:file=[%s], attrid=%d, name=[%s], size=%ld\n", relpath, (int)attrcnt, buffer+pos, (long)attrsize);
if ((attrsize>0) && (attrsize>65535LL))
if (attrsize>65535LL)
{ errprintf("file [%s] has an xattr [%s] with data too big (size=%ld, maxsize=64k)\n", relpath, buffer+pos, (long)attrsize);
ret=-1;
continue; // copy the next xattr
Expand Down Expand Up @@ -311,7 +311,7 @@ int createar_item_xattr(csavear *save, char *root, char *relpath, struct stat64
free(valbuf);
continue; // copy the next xattr
}
else if (errno==ENOATTR) // if the attribute does not exist
else // errno==ENOATTR hence the attribute does not exist
{
msgprintf(MSG_VERB2, " xattr:lgetxattr-win(%s,%s)=-1: errno==ENOATTR\n", relpath, buffer+pos);
free(valbuf);
Expand Down Expand Up @@ -353,7 +353,7 @@ int createar_item_winattr(csavear *save, char *root, char *relpath, struct stat6
continue; // ignore the current xattr
}
msgprintf(MSG_VERB2, " winattr:file=[%s], attrcnt=%d, name=[%s], size=%ld\n", relpath, (int)attrcnt, winattr[i], (long)attrsize);
if ((attrsize>0) && (attrsize>65535LL))
if (attrsize>65535LL)
{
errprintf("file [%s] has an xattr [%s] with data size=%ld too big (max xattr size is 65535)\n", relpath, winattr[i], (long)attrsize);
ret=-1;
Expand Down Expand Up @@ -384,15 +384,11 @@ int createar_item_winattr(csavear *save, char *root, char *relpath, struct stat6
free(valbuf);
continue; // ignore the current xattr
}
else if (errno==ENOATTR) // if the attribute does not exist
else // errno==ENOATTR hence the attribute does not exist
{
msgprintf(MSG_VERB2, " winattr:lgetxattr-win(%s,%s)=-1: errno==ENOATTR\n", relpath, winattr[i]);
free(valbuf);
}
else
{
free(valbuf);
}
}

return ret;
Expand Down Expand Up @@ -581,7 +577,7 @@ int createar_save_file(csavear *save, char *root, char *relpath, struct stat64 *
cdico *dicoattr;
int attrerrors=0;
u64 filecost;
u64 progress;
s64 progress;
int objtype;
int res;

Expand Down
12 changes: 6 additions & 6 deletions src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ s64 queue_dequeue_block(cqueue *q, cblockinfo *blkinfo)
return FSAERR_ENDOFFILE;
}

// should not happen since queuelocked_is_first_block_ready means there is at least one block in the queue
assert((cur=q->head)!=NULL);
cur=q->head;
assert(cur!=NULL); // queuelocked_is_first_block_ready means there is at least one block in the queue

// test the first item
if ((cur->type==QITEM_TYPE_BLOCK) && (cur->status==QITEM_STATUS_DONE))
Expand Down Expand Up @@ -581,8 +581,8 @@ s64 queue_dequeue_header_internal(cqueue *q, cheadinfo *headinfo)
return FSAERR_ENDOFFILE;
}

// should not happen since queuelocked_is_first_block_ready means there is at least one block in the queue
assert ((cur=q->head)!=NULL);
cur=q->head;
assert (cur!=NULL); // queuelocked_is_first_block_ready means there is at least one block in the queue

// test the first item
switch (cur->type)
Expand Down Expand Up @@ -712,8 +712,8 @@ s64 queue_destroy_first_item(cqueue *q)
return FSAERR_ENDOFFILE;
}

// should not happen since queuelocked_is_first_block_ready means there is at least one block in the queue
assert((cur=q->head)!=NULL);
cur=q->head;
assert(cur!=NULL); // queuelocked_is_first_block_ready means there is at least one block in the queue

switch (cur->type)
{
Expand Down
2 changes: 1 addition & 1 deletion src/thread_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int compress_block_generic(struct s_blockinfo *blkinfo)
}
if ((res=crypto_blowfish(blkinfo->blkcompsize, &cryptsize, (u8*)bufcomp, (u8*)bufcrypt,
g_options.encryptpass, strlen((char*)g_options.encryptpass), 1))!=0)
{ errprintf("crypt_block_blowfish() failed\n");
{ errprintf("crypt_block_blowfish() failed with res=%d\n", res);
return -1;
}
free(bufcomp);
Expand Down

0 comments on commit c6ba47f

Please sign in to comment.