n8gray/Backup-Bouncer

xattr-util.c compiler warnings, with fixes

Opened this issue · 0 comments

I just downloaded and built Backup-Bouncer with the latest LLVM compiler (Xcode 4.5.2). make throws several compiler warnings, which should be addressed:

marchhare:~ james$ cd /Users/james/Development/software/Backup\ Bouncer/backup-bouncer-0.2.0\ 2
marchhare:backup-bouncer-0.2.0 2 james$ make
cd util && make
cc -Wall xattr-util.c -o xattr-util
xattr-util.c:17:23: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
if (read_size >= 0) {
~~~~~~~~~ ^ ~
xattr-util.c:70:18: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (size < 0) {
~~~~ ^ ~
xattr-util.c:76:18: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (size < 0) {
~~~~ ^ ~
xattr-util.c:96:18: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (size < 0) {
~~~~ ^ ~
xattr-util.c:102:18: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (size < 0) {
~~~~ ^ ~
xattr-util.c:107:15: warning: unused variable 'value' [-Wunused-variable]
void *value;
^
6 warnings generated.

Specifically, there are a couple of variables named 'size' used to store the result of getxattr() and listxattr(). The problem is that they are size_t vars, but getxattr() and listxattr() return ssize_t. The subsequent tests to see if size if negative are meaningless.

Finally, there's an unused variable.

Here's the fixes that correct the problems and eliminate the compiler warnings:

16c16
< size_t read_size = getxattr(file, name, result, size, 0, options);


    ssize_t read_size = getxattr(file, name, result, size, 0, options);

66c66
< size_t size = listxattr(argv[2], NULL, 0, options);

    ssize_t size = listxattr(argv[2], NULL, 0, options);

92c92
< size_t size = listxattr(argv[2], NULL, 0, options);

    ssize_t size = listxattr(argv[2], NULL, 0, options);

107c107
< void *value;

    //void *value;