[PATCH] fix build error in latest git (unsigned/signed comparison)

Andres Salomon dilinger at collabora.co.uk
Sat Aug 8 16:57:58 PDT 2009


From 67e49b800a14363c93eeab362e202e68362b7775 Mon Sep 17 00:00:00 2001
From: Andres Salomon <dilinger at collabora.co.uk>
Date: Sat, 8 Aug 2009 19:54:35 -0400
Subject: [PATCH] Fix signed/unsigned comparison build error
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Latest git has the following issue when building:

cc -DHAVE_CONFIG_H -I. -I.. -I../include -I..   -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include   -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include   -I../gdbus -I../gatchat -I.. -DPLUGINDIR=\""/home/dilinger/ofono/plugins/.libs"\" -g -O2 -g -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align -MT sim.o -MD -MP -MF .deps/sim.Tpo -c -o sim.o sim.c
cc1: warnings being treated as errors
sim.c: In function ‘sim_op_check_cached’:
sim.c:795: error: comparison between signed and unsigned

The code in question is:
        if (TFR(read(fd, buffer, file_length)) < file_length)

The fix for this is to simply cast the result to unsigned after ensuring
that it's not negative.
---
 src/sim.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/sim.c b/src/sim.c
index 1271ded..2c3b41b 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -792,7 +792,8 @@ static gboolean sim_op_check_cached(struct ofono_modem *modem)
 
 	buffer = g_malloc(file_length);
 
-	if (TFR(read(fd, buffer, file_length)) < file_length)
+	len = TFR(read(fd, buffer, file_length));
+	if (len < 0 || ((unsigned int) len < file_length))
 		goto cleanup;
 
 	for (record = 0; record < file_length / record_length; record++) {
-- 
1.6.3.3



More information about the ofono mailing list