pike.git/
src/
stralloc.c
Branch:
Tag:
Non-build tags
All tags
No tags
2003-03-17
2003-03-17 16:44:23 by Henrik Grubbström (Grubba) <grubba@grubba.org>
a54964e4bab0c8afb2be75c5d4f03e638c2c0731 (
34
lines) (+
21
/-
13
)
[
Show
|
Annotate
]
Branch:
7.9
STRTOL{,_PCHARP}() fixes.
Rev: src/port.c:1.66
Rev: src/stralloc.c:1.154
2:
|| This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: stralloc.c,v 1.
153
2003/03/
14
15
:
50
:
47
grubba Exp $
+
|| $Id: stralloc.c,v 1.
154
2003/03/
17
16
:
44
:
23
grubba Exp $
*/ #include "global.h"
24:
#include <ctype.h> #include <math.h>
-
RCSID("$Id: stralloc.c,v 1.
153
2003/03/
14
15
:
50
:
47
grubba Exp $");
+
RCSID("$Id: stralloc.c,v 1.
154
2003/03/
17
16
:
44
:
23
grubba Exp $");
/* #define STRALLOC_USE_PRIMES */
42:
#endif
+
#if (SIZEOF_LONG == 4) && defined(_LP64)
+
/* Kludge for gcc and the system header files not using the same model... */
+
#undef LONG_MIN
+
#undef LONG_MAX
+
#undef ULONG_MAX
+
#define LONG_MIN INT_MIN
+
#define LONG_MAX INT_MAX
+
#define ULONG_MAX UINT_MAX
+
#endif
#if PIKE_RUN_UNLOCKED /* Make this bigger when we get lightweight threads */
2223:
c = EXTRACT_PCHARP(str); /* skip over leading "0x" or "0X" */ }
+
mul_limit = ((unsigned long)LONG_MAX)/base;
+
add_limit = (int) (LONG_MAX % base);
if (neg) {
-
mul
_limit =
(unsigned long
)
LONG_MIN
/
base;
-
add_limit =
(int)
((unsigned
long)
LONG_MIN
%
base)
;
+
if (++add
_limit =
=
base
)
{
+
add_limit =
0;
+
mul_limit++
;
}
-
else {
-
mul_limit = LONG_MAX / base;
-
add_limit = (int) (LONG_MAX % base);
+
} val=DIGIT(c);
2238:
INC_PCHARP(str,1); c=EXTRACT_PCHARP(str); if(!(WIDE_ISALNUM(c) && (xx=DIGIT(c)) < base)) break;
-
if (val > mul_limit || (val == mul_limit && xx > add_limit))
+
if (val > mul_limit || (val == mul_limit && xx > add_limit))
{
overflow = 1;
-
else
+
}
else
val = base * val + xx; }
2251:
} else { if (neg)
-
return
val >
(
unsigned
long)
LONG_MAX ?
-
-
(
long) (
val
-
(unsigned long
)
LONG_MAX) - LONG_MAX :
-
-(long) val
;
+
return (long)(
~
val
+
1
);
else return (long) val; }