Ticket #11647: 0001-stdint.h-use-correct-type-for-INT64_MAX.patch

File 0001-stdint.h-use-correct-type-for-INT64_MAX.patch, 1.4 KB (added by Timothy_Gu, 9 years ago)

Patch fixing the issue

  • headers/posix/stdint.h

    From 77f595cf43ee90afc8ff61ab3f288a5a3016871a Mon Sep 17 00:00:00 2001
    From: Timothy Gu <timothygu99@gmail.com>
    Date: Fri, 19 Dec 2014 15:16:47 -0800
    Subject: [PATCH] stdint.h: use correct type for INT64_MAX
    
    int64_t is signed. Although it does not make a difference by itself, because
    INT64_MAX is still a valid number for uint64_t (UL), the later INT64_MIN
    declaration depends on INT64_MAX, and therefore got implicitly casted to
    unsigned type.
    
    This fixes the following program on a x86_64 system:
    
    	#include <stdint.h>
    
    	int main() {
    		int64_t test = 5;
    		if (test < INT64_MIN)
    			return 1;
    		return 0;
    	}
    
    This is a regression since commit 1d13a609 ("stdint.h: define [U]INT64[MAX|MIN]
    with [U]L on x86_64").
    
    Signed-off-by: Timothy Gu <timothygu99@gmail.com>
    ---
     headers/posix/stdint.h | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/headers/posix/stdint.h b/headers/posix/stdint.h
    index 03e6695..b90fca2 100644
    a b typedef uint64_t uintmax_t;  
    7070#define UINT32_MAX  (4294967295U)
    7171
    7272#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ > 4
    73 #define INT64_MAX   (9223372036854775807UL)
     73#define INT64_MAX   (9223372036854775807L)
    7474#define UINT64_MAX  (18446744073709551615UL)
    7575#else
    76 #define INT64_MAX   (9223372036854775807ULL)
     76#define INT64_MAX   (9223372036854775807LL)
    7777#define UINT64_MAX  (18446744073709551615ULL)
    7878#endif
    7979#define INT64_MIN   (-INT64_MAX-1)