Skip to contentSkip to conversation

Fixed compiler warnings reported on Ubuntu 10.04

PATCH Applied David Sommerseth 4 participants 4 messages Sep 17, 2010 – Sep 18, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fixed compiler warnings reported on Ubuntu 10.04

The warnings reported where:
--------------------------------------------------------
misc.c:158: warning: ignoring return value of ‘nice’, declared with attribute warn_unused_result options.c:4033: warning: format not a string literal and no format arguments options.c:4043: warning: format not a string literal and no format arguments options.c:4053: warning: format not a string literal and no format arguments push.c:182: warning: format not a string literal and no format arguments
push.c:199: warning: format not a string literal and no format arguments
push.c:235: warning: format not a string literal and no format arguments
status.c:171: warning: ignoring return value of ‘ftruncate’, declared with attribute warn_unused_result
--------------------------------------------------------

---
 misc.c    |    5 ++---
 options.c |    6 +++---
 push.c    |    6 +++---
 status.c  |    4 +++-
 4 files changed, 11 insertions(+), 10 deletions(-)
misc.c +2 -3
index eafd892..1e863f2 100644
@@ -155,9 +155,8 @@ set_nice (int niceval)
     {
 #ifdef HAVE_NICE
       errno = 0;
-      nice (niceval);
-      if (errno != 0)
-	msg (M_WARN | M_ERRNO, "WARNING: nice %d failed", niceval);
+      if (nice (niceval) < 0 && errno != 0)
+	msg (M_WARN | M_ERRNO, "WARNING: nice %d failed: %s", niceval, strerror(errno));
       else
 	msg (M_INFO, "nice %d succeeded", niceval);
 #else
options.c +3 -3
index d40c7f0..3d0c5e3 100644
@@ -4030,7 +4030,7 @@ add_option (struct options *options,
 		    {
 		      if (options->inetd != -1)
 			{
-			  msg (msglevel, opterr);
+			  msg (msglevel, "%s", opterr);
 			  goto err;
 			}
 		      else
@@ -4040,7 +4040,7 @@ add_option (struct options *options,
 		    {
 		      if (options->inetd != -1)
 			{
-			  msg (msglevel, opterr);
+			  msg (msglevel, "%s", opterr);
 			  goto err;
 			}
 		      else
@@ -4050,7 +4050,7 @@ add_option (struct options *options,
 		    {
 		      if (name != NULL)
 			{
-			  msg (msglevel, opterr);
+			  msg (msglevel, "%s", opterr);
 			  goto err;
 			}
 		      name = p[z];
push.c +3 -3
index 1320bec..40e64c3 100644
@@ -179,7 +179,7 @@ send_push_reply (struct context *c)
   const int safe_cap = BCAP (&buf) - extra;
   bool push_sent = false;
 
-  buf_printf (&buf, cmd);
+  buf_printf (&buf, "%s", cmd);
 
   while (e)
     {
@@ -196,7 +196,7 @@ send_push_reply (struct context *c)
 		push_sent = true;
 		multi_push = true;
 		buf_reset_len (&buf);
-		buf_printf (&buf, cmd);
+		buf_printf (&buf, "%s", cmd);
 	      }
 	    }
 	  if (BLEN (&buf) + l >= safe_cap)
@@ -232,7 +232,7 @@ send_push_reply (struct context *c)
       bool status = false;
 
       buf_reset_len (&buf);
-      buf_printf (&buf, cmd);
+      buf_printf (&buf, "%s", cmd);
       status = send_control_channel_string (c, BSTR(&buf), D_PUSH);
       if (!status)
 	goto fail;
status.c +3 -1
index 92fc7bc..dd6fe1e 100644
@@ -168,7 +168,9 @@ status_flush (struct status_output *so)
 #if defined(HAVE_FTRUNCATE)
       {
 	const off_t off = lseek (so->fd, (off_t)0, SEEK_CUR);
-	ftruncate (so->fd, off);
+	if (ftruncate (so->fd, off) != 0) {
+	  msg (M_WARN, "Failed to truncate status file: %s", strerror(errno));
+	}
       }
 #elif defined(HAVE_CHSIZE)
       {
Signature · 1 line
1.7.2.3
#1 lore raw

Hi,

misc.c

Quoted 2 lines · David Sommerseth
misc.c +0 -0
index eafd892..1e863f2 100644

ACK. Good programming practice.

The format string stuff might be harmless right now (if the input is well-controlled) but might it's still good practice to be explicit about it "this is a string, no more".

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
Acked-by on v1 1/1
#2 lore raw
In reply to David Sommerseth
Quoted 12 lines · David Sommerseth

The warnings reported where:
--------------------------------------------------------
misc.c:158: warning: ignoring return value of ‘nice’, declared with attribute warn_unused_result options.c:4033: warning: format not a string literal and no format arguments options.c:4043: warning: format not a string literal and no format arguments options.c:4053: warning: format not a string literal and no format arguments push.c:182: warning: format not a string literal and no format arguments
push.c:199: warning: format not a string literal and no format arguments
push.c:235: warning: format not a string literal and no format arguments
status.c:171: warning: ignoring return value of ‘ftruncate’, declared with attribute warn_unused_result
--------------------------------------------------------

Quoted 1 line
#3 lore raw
In reply to David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 12 lines · David Sommerseth

The warnings reported where:
--------------------------------------------------------
misc.c:158: warning: ignoring return value of ‘nice’, declared with attribute warn_unused_result options.c:4033: warning: format not a string literal and no format arguments options.c:4043: warning: format not a string literal and no format arguments options.c:4053: warning: format not a string literal and no format arguments push.c:182: warning: format not a string literal and no format arguments
push.c:199: warning: format not a string literal and no format arguments
push.c:235: warning: format not a string literal and no format arguments
status.c:171: warning: ignoring return value of ‘ftruncate’, declared with attribute warn_unused_result
--------------------------------------------------------

Quoted 8 lines
---
 misc.c    |    5 ++---
 options.c |    6 +++---
 push.c    |    6 +++---
 status.c  |    4 +++-
 4 files changed, 11 insertions(+), 10 deletions(-)

Applied to the bugfix2.1 branch. Will be merged into the allmerged and beta2.2 branches in the near future.

commit d3d6d1cbdaca58d7c785ef7898d1134007fbc323

    Signed-off-by: David Sommerseth <[email protected]...>
    Acked-by: Gert Doering <[email protected]...>
    Acked-by: Peter Stuge <[email protected]...>

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkyUhswACgkQDC186MBRfrpMyQCcC2CrTPbL0uNenoIF24IVDqnH RvMAn3j8hUmPxW6O8286NIGH32a6xRdY
=S/eD
-----END PGP SIGNATURE-----