summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-07-16 12:58:54 +0100
committerRichard Jones <rjones@redhat.com>2010-07-16 15:23:27 +0100
commit321ca1ef91a90cec5b94058b84420e8018e3f1d8 (patch)
treec943964a59c946df961a91bc05bf7de970c7e8f8 /src
parentaac51942aab63a9355ad6724345ea923148bf2a9 (diff)
downloadlibguestfs-321ca1ef91a90cec5b94058b84420e8018e3f1d8.tar.gz
libguestfs-321ca1ef91a90cec5b94058b84420e8018e3f1d8.tar.xz
libguestfs-321ca1ef91a90cec5b94058b84420e8018e3f1d8.zip
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: http://www.airs.com/blog/archives/120
Diffstat (limited to 'src')
-rwxr-xr-xsrc/generator.ml49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/generator.ml b/src/generator.ml
index cb3f7739..d427558c 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -6034,7 +6034,7 @@ check_state (guestfs_h *g, const char *caller)
| StringList _ | DeviceList _ -> true
| _ -> false) (snd style) in
if needs_i then (
- pr " int i;\n";
+ pr " size_t i;\n";
pr "\n"
);
@@ -6487,7 +6487,7 @@ and generate_daemon_actions () =
pr " * and perform device name translation.\n";
pr " */\n";
pr " {\n";
- pr " int i;\n";
+ pr " size_t i;\n";
pr " for (i = 0; %s[i] != NULL; ++i)\n" n;
pr " RESOLVE_DEVICE (%s[i], %s, goto done);\n" n
(if is_filein then "cancel_receive ()" else "0");
@@ -6637,7 +6637,7 @@ and generate_daemon_actions () =
pr "static int lvm_tokenize_%s (char *str, guestfs_int_lvm_%s *r)\n" typ typ;
pr "{\n";
pr " char *tok, *p, *next;\n";
- pr " int i, j;\n";
+ pr " size_t i, j;\n";
pr "\n";
(*
pr " fprintf (stderr, \"%%s: <<%%s>>\\n\", __func__, str);\n";
@@ -6862,7 +6862,7 @@ static void print_error (guestfs_h *g, void *data, const char *msg)
/* FIXME: nearly identical code appears in fish.c */
static void print_strings (char *const *argv)
{
- int argc;
+ size_t argc;
for (argc = 0; argv[argc] != NULL; ++argc)
printf (\"\\t%%s\\n\", argv[argc]);
@@ -6871,7 +6871,7 @@ static void print_strings (char *const *argv)
/*
static void print_table (char const *const *argv)
{
- int i;
+ size_t i;
for (i = 0; argv[i] != NULL; i += 2)
printf (\"%%s: %%s\\n\", argv[i], argv[i+1]);
@@ -7526,7 +7526,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd =
| RString _ -> pr " char *r;\n"; "NULL"
| RStringList _ | RHashtable _ ->
pr " char **r;\n";
- pr " int i;\n";
+ pr " size_t i;\n";
"NULL"
| RStruct (_, typ) ->
pr " struct guestfs_%s *r;\n" typ; "NULL"
@@ -8106,7 +8106,7 @@ static const char *const commands[] = {
static char *
generator (const char *text, int state)
{
- static int index, len;
+ static size_t index, len;
const char *name;
if (!state) {
@@ -8413,7 +8413,7 @@ copy_table (char * const * argv)
{
CAMLparam0 ();
CAMLlocal5 (rv, pairv, kv, vv, cons);
- int i;
+ size_t i;
rv = Val_int (0);
for (i = 0; argv[i] != NULL; i += 2) {
@@ -8596,7 +8596,7 @@ copy_table (char * const * argv)
pr " const char *r;\n"; "NULL"
| RString _ -> pr " char *r;\n"; "NULL"
| RStringList _ ->
- pr " int i;\n";
+ pr " size_t i;\n";
pr " char **r;\n";
"NULL"
| RStruct (_, typ) ->
@@ -8604,7 +8604,7 @@ copy_table (char * const * argv)
| RStructList (_, typ) ->
pr " struct guestfs_%s_list *r;\n" typ; "NULL"
| RHashtable _ ->
- pr " int i;\n";
+ pr " size_t i;\n";
pr " char **r;\n";
"NULL"
| RBufferOut _ ->
@@ -8994,7 +8994,7 @@ close (g)
| RStringList n | RHashtable n ->
pr "PREINIT:\n";
pr " char **%s;\n" n;
- pr " int i, n;\n";
+ pr " size_t i, n;\n";
pr " PPCODE:\n";
pr " %s = guestfs_%s " n name;
generate_c_call_args ~handle:"g" style;
@@ -9038,7 +9038,7 @@ close (g)
and generate_perl_struct_list_code typ cols name style n do_cleanups =
pr "PREINIT:\n";
pr " struct guestfs_%s_list *%s;\n" typ n;
- pr " int i;\n";
+ pr " size_t i;\n";
pr " HV *hv;\n";
pr " PPCODE:\n";
pr " %s = guestfs_%s " n name;
@@ -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);
@@ -9364,7 +9364,12 @@ get_string_list (PyObject *obj)
return NULL;
}
- len = PyList_Size (obj);
+ Py_ssize_t slen = PyList_Size (obj);
+ if (slen == -1) {
+ PyErr_SetString (PyExc_RuntimeError, \"get_string_list: PyList_Size failure\");
+ return NULL;
+ }
+ len = (size_t) slen;
r = malloc (sizeof (char *) * (len+1));
if (r == NULL) {
PyErr_SetString (PyExc_RuntimeError, \"get_string_list: out of memory\");
@@ -9462,7 +9467,7 @@ py_guestfs_close (PyObject *self, PyObject *args)
pr "put_%s_list (struct guestfs_%s_list *%ss)\n" typ typ typ;
pr "{\n";
pr " PyObject *list;\n";
- pr " int i;\n";
+ pr " size_t i;\n";
pr "\n";
pr " list = PyList_New (%ss->len);\n" typ;
pr " for (i = 0; i < %ss->len; ++i)\n" typ;
@@ -9960,7 +9965,7 @@ static VALUE ruby_guestfs_close (VALUE gv)
pr " char **%s;\n" n;
pr " Check_Type (%sv, T_ARRAY);\n" n;
pr " {\n";
- pr " int i, len;\n";
+ pr " size_t i, len;\n";
pr " len = RARRAY_LEN (%sv);\n" n;
pr " %s = guestfs_safe_malloc (g, sizeof (char *) * (len+1));\n"
n;
@@ -10032,7 +10037,7 @@ static VALUE ruby_guestfs_close (VALUE gv)
pr " free (r);\n";
pr " return rv;\n";
| RStringList _ ->
- pr " int i, len = 0;\n";
+ pr " size_t i, len = 0;\n";
pr " for (i = 0; r[i] != NULL; ++i) len++;\n";
pr " VALUE rv = rb_ary_new2 (len);\n";
pr " for (i = 0; r[i] != NULL; ++i) {\n";
@@ -10049,7 +10054,7 @@ static VALUE ruby_guestfs_close (VALUE gv)
generate_ruby_struct_list_code typ cols
| RHashtable _ ->
pr " VALUE rv = rb_hash_new ();\n";
- pr " int i;\n";
+ pr " size_t i;\n";
pr " for (i = 0; r[i] != NULL; i+=2) {\n";
pr " rb_hash_aset (rv, rb_str_new2 (r[i]), rb_str_new2 (r[i+1]));\n";
pr " free (r[i]);\n";
@@ -10118,7 +10123,7 @@ and generate_ruby_struct_code typ cols =
(* Ruby code to return a struct list. *)
and generate_ruby_struct_list_code typ cols =
pr " VALUE rv = rb_ary_new2 (r->len);\n";
- pr " int i;\n";
+ pr " size_t i;\n";
pr " for (i = 0; i < r->len; ++i) {\n";
pr " VALUE hv = rb_hash_new ();\n";
List.iter (
@@ -10525,7 +10530,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close
| DeviceList _ -> true
| _ -> false) (snd style) in
if needs_i then
- pr " int i;\n";
+ pr " size_t i;\n";
pr "\n";
@@ -11177,7 +11182,7 @@ namespace Guestfs
pr " return r != 0 ? true : false;\n"
| RHashtable _ ->
pr " Hashtable rr = new Hashtable ();\n";
- pr " for (int i = 0; i < r.Length; i += 2)\n";
+ pr " for (size_t i = 0; i < r.Length; i += 2)\n";
pr " rr.Add (r[i], r[i+1]);\n";
pr " return rr;\n"
| RInt _ | RInt64 _ | RConstString _ | RConstOptString _
@@ -11214,7 +11219,7 @@ and generate_bindtests () =
static void
print_strings (char *const *argv)
{
- int argc;
+ size_t argc;
printf (\"[\");
for (argc = 0; argv[argc] != NULL; ++argc) {