Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
xdu: Initialize variables name in all cases
Clang 4.0.0 warns about the use of a possibly uninitialized variable.

```
$ CC=clang make
clang -Wall -Werror -Wextra -pedantic -std=gnu99   -c -o xdu.o xdu.c
xdu.c:887:5: error: variable 'name' is used uninitialized whenever switch default is taken [-Werror,-Wsometimes-uninitialized]
    default:
    ^~~~~~~
xdu.c:892:78: note: uninitialized use occurs here
    fprintpstext(fp, rect.left + 4, rect.top + (rect.height - rect.top) / 2, name);
                                                                             ^~~~
xdu.c:868:28: note: initialize the variable 'name' to silence this warning
    char label[1024], *name;
                           ^
                            = NULL
1 error generated.
```

Only the function `a_saveps()` is the caller of that path, and passes
`res.showsize()`. Maybe that parameter should be checked by the caller
and an assert be added.

Setting the variable to NULl fixes the issue.
  • Loading branch information
pmenzel committed Jul 18, 2017
1 parent d44cc5d commit efa72d7
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions xdu.c
Expand Up @@ -885,6 +885,7 @@ void savepsnode(FILE * fp, struct node *nodep, struct rect rect, int showsize)
name = label;
break;
default:
name = NULL;
break;
}

Expand Down

0 comments on commit efa72d7

Please sign in to comment.