bug-recutils
[Top][All Lists]
Advanced

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

Re: [bug-recutils] recfix tests fail on Ubuntu 64-Bit systems


From: Daiki Ueno
Subject: Re: [bug-recutils] recfix tests fail on Ubuntu 64-Bit systems
Date: Mon, 16 May 2011 15:02:15 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Hi,

address@hidden (Jose E. Marchesi) writes:
>     
>     But at a closer look, using "-O0 -g"
>     fixed 2 tests of "make check":
>     
>       recfix-size-exact-zero ok
>     
>       recfix-size-exact ok
>     
>     
>     So, I can not reproduce it completely.
>     The other ones remain...
>
> I will try to get access to a macosx machine.

I saw the same issue when packaging recutils on Fedora 15 (x86_64).
After quick look at the code, the following part looks questionable:

rec-utils.c:290

size_t
rec_extract_size (char *str)
{
  ...
  size_t res;
  ...
  rec_parse_int (&p, (int *) &res);

On LP64 systems, int is 32 bit while size_t (unsigned long) is 64 bit.
So casting return pointers like this does not work as expected.  Try:

#include <stdio.h>

int main (int argc, char **argv)
{
  size_t res = 1UL << 32;
  int *i = (int *) &res;

  printf ("%lx\n", res);
  *i = 2;
  printf ("%lx\n", res);
  return 0;
}

You will see:

100000000
100000002

Patch attached.

>From ac373461c77420992147023e2db5a4fcd9933035 Mon Sep 17 00:00:00 2001
From: Daiki Ueno <address@hidden>
Date: Mon, 16 May 2011 15:00:39 +0900
Subject: [PATCH] Fix size constraint handling on LP64 systems.

---
 src/rec-utils.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/rec-utils.c b/src/rec-utils.c
index a79c24d..bab1927 100644
--- a/src/rec-utils.c
+++ b/src/rec-utils.c
@@ -290,7 +290,7 @@ rec_extract_size (char *str)
 {
   char *p;
   char *condition_str;
-  size_t res;
+  int res;
 
   if (!rec_match (str, REC_INT_SIZE_RE))
     {
@@ -301,9 +301,9 @@ rec_extract_size (char *str)
   rec_skip_blanks (&p);
   rec_parse_regexp (&p, "^[><]=?", &condition_str);
   rec_skip_blanks (&p);
-  rec_parse_int (&p, (int *) &res);
+  rec_parse_int (&p, &res);
 
-  return res;
+  return (size_t) res;
 }
 
 enum rec_size_condition_e
-- 
1.7.5.1

Regards,
-- 
Daiki Ueno

reply via email to

[Prev in Thread] Current Thread [Next in Thread]