[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH 3/3] Use an unsigned type (size_t) for all loop iterators.

On 16/07/10 13:05, Richard W.M. Jones wrote:
From 460031c9f9bcabd5e132aab22ab0d001ab14d33d Mon Sep 17 00:00:00 2001
From: Richard Jones<rjones redhat com>
Date: Fri, 16 Jul 2010 12:58:54 +0100
Subject: [PATCH 3/3] Use an unsigned type (size_t) for all loop iterators.

This resolves a warning from gcc 4.5:
   assuming signed overflow does not occur when simplifying
     conditional to constant

This page explains the issues in some detail:
  configure.ac     |    1 -
  src/generator.ml |   42 +++++++++++++++++++++---------------------
  2 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/configure.ac b/configure.ac
index caf25ee..671fbb0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,7 +110,6 @@ if test "$gl_gcc_warnings" = yes; then
    nw="$nw -Wmissing-format-attribute" # daemon.h's asprintf_nowarn
    nw="$nw -Winline"                 # daemon.h's asprintf_nowarn
    nw="$nw -Wshadow"                 # numerous, plus we're not unanimous
-  # ?? -Wstrict-overflow
    nw="$nw -Wunsafe-loop-optimizations" # just a warning that an optimization
                                      # was not possible, safe to ignore
    nw="$nw -Wpacked"                 # Allow attribute((packed)) on structs
diff --git a/src/generator.ml b/src/generator.ml
index cb3f773..8fc619f 100755
--- a/src/generator.ml
+++ b/src/generator.ml


@@ -9354,7 +9354,7 @@ put_handle (guestfs_h *g)
  static char **
  get_string_list (PyObject *obj)
-  int i, len;
+  size_t i, len;
    char **r;

    assert (obj);

This isn't safe. len is assigned later:

  len = PyList_Size (obj);

PyList_Size returns Py_ssize_t, which is a signed type. This may also mean that the later code may also need a second look, as it doesn't check for a negative return value.

The rest all look fine, though.

Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team

GPG ID:  D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]