[sane-devel] [PATCH] backend/hp.c: Remove tautological if condition to remove build warning

Paul Menzel paulepanter at users.sourceforge.net
Fri Feb 15 13:18:33 UTC 2013

Date: Fri, 15 Feb 2013 14:02:42 +0100

Building SANE default configuration with Clang 3.2 the following warning
is generated.

        $ clang --version
        Debian clang version 3.2-1~exp5 (tags/RELEASE_32/final) (based on LLVM 3.2)
        Target: i386-pc-linux-gnu
        Thread model: posix
        $ CC=clang ./configure
        $ make
        /bin/sh ../libtool --silent  --tag=CC   --mode=compile clang -DHAVE_CONFIG_H -I. -I../include/sane -I/usr/local/include -I. -I. -I../include -I../include -DLIBDIR="/usr/local/lib/sane" -DBACKEND_NAME=hp -DPATH_SANE_CONFIG_DIR=/usr/local/etc/sane.d 	  -DPATH_SANE_DATA_DIR=/usr/local/share 	  -DPATH_SANE_LOCK_DIR=/usr/local/var/lock/sane 	  -DV_MAJOR=1 -DV_MINOR=0  -g -O2 -W -Wall -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes -pedantic -ansi -MT libhp_la-hp.lo -MD -MP -MF .deps/libhp_la-hp.Tpo -c -o libhp_la-hp.lo `test -f 'hp.c' || echo './'`hp.c
        hp.c:590:7: warning: variable 'new' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
          if (!ptr)
        hp.c:601:59: note: uninitialized use occurs here
          RETURN_IF_FAIL( hp_device_list_add(&global.device_list, new) );
        ./hp.h:83:25: note: expanded from macro 'RETURN_IF_FAIL'
          SANE_Status status = (try);                                           \
        hp.c:590:3: note: remove the 'if' if its condition is always true
          if (!ptr)
        hp.c:563:15: note: initialize the variable 'new' to silence this warning
          HpDevice      new;
                            = NULL
        1 warning generated.

And indeed the `if` condition is always true as the `for` loop only
exists if `ptr` is `NULL`.

The proposal to silence the warning by setting `new` to NULL is not used
as then a NULL device would be added to the device list in
`RETURN_IF_FAIL( hp_device_list_add(&global.device_list, new) );`.
 backend/hp.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/backend/hp.c b/backend/hp.c
index c85e40c..5810254 100644
--- a/backend/hp.c
+++ b/backend/hp.c
@@ -587,13 +587,10 @@ hp_get_dev (const char *devname, HpDevice* devp)
   DBG(3, "hp_get_dev: New device %s, connect-%s, scsi-request=%lu\n",
       devname, connect, (unsigned long)info->config.use_scsi_request);
-  if (!ptr)
-  {
-     status =  sanei_hp_device_new (&new, devname);
+  status = sanei_hp_device_new (&new, devname);
-     if ( status != SANE_STATUS_GOOD )
-       return status;
-  }
+  if ( status != SANE_STATUS_GOOD )
+     return status;
   if (devp)
       *devp = new;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.alioth.debian.org/pipermail/sane-devel/attachments/20130215/c7337985/attachment.pgp>

More information about the sane-devel mailing list