pike.git
/
src
/
operators.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/operators.c:1:
/* || 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: operators.c,v 1.
231
2008/05/
03
15
:
29
:
24
nilsson
Exp $
+
|| $Id: operators.c,v 1.
232
2008/05/
21
21
:
13
:
04
mast
Exp $
*/ #include "global.h" #include <math.h> #include "interpret.h" #include "svalue.h" #include "multiset.h" #include "mapping.h" #include "array.h" #include "stralloc.h"
pike.git/src/operators.c:1545:
} #endif /* PIKE_DEBUG */ /* Adjust the stack. */ save_sp[-args] = sp[-1]; sp = save_sp + 1 - args; return; } else { e = -args; }
+
/* These calculations should always give some margin based on the size. */
+
/* One extra char for the sign. */
+
#define MAX_INT_SPRINTF_LEN (1 + (SIZEOF_INT_TYPE * 5 + 1) / 2)
+
/* Six extra chars: Mantissa sign, decimal point, zero before the
+
* decimal point, the 'e', exponent sign, and an extra digit due
+
* to the mantissa/exponent split. */
+
#define MAX_FLOAT_SPRINTF_LEN (6 + (SIZEOF_FLOAT_TYPE * 5 + 1) / 2)
size=0; for(e=-args;e<0;e++) { switch(sp[e].type) { case T_STRING: size+=sp[e].u.string->len; if(sp[e].u.string->size_shift > max_shift) max_shift=sp[e].u.string->size_shift; break; case T_INT:
-
size+
=
14
;
+
size +
=
MAX_INT_SPRINTF_LEN
;
break; case T_FLOAT:
-
size+
=
22
;
+
size +
=
MAX_FLOAT_SPRINTF_LEN
;
break; } } r=begin_wide_shared_string(size,max_shift); buf=MKPCHARP_STR(r); size=0; for(e=-args;e<0;e++) { switch(sp[e].type) { case T_STRING: pike_string_cpy(buf,sp[e].u.string); INC_PCHARP(buf,sp[e].u.string->len); break; case T_INT: sprintf(buffer,"%"PRINTPIKEINT"d",sp[e].u.integer);
-
+
#ifdef PIKE_DEBUG
+
if (strlen (buffer) > MAX_INT_SPRINTF_LEN)
+
Pike_fatal ("Formatted integer %s is %"PRINTSIZET"u, "
+
"longer than assumed max %"PRINTSIZET"u.\n",
+
buffer, strlen (buffer), MAX_INT_SPRINTF_LEN);
+
#endif
goto append_buffer; case T_FLOAT: sprintf(buffer,"%"PRINTPIKEFLOAT"f",sp[e].u.float_number);
-
+
#ifdef PIKE_DEBUG
+
if (strlen (buffer) > MAX_FLOAT_SPRINTF_LEN)
+
Pike_fatal ("Formatted float %s is %"PRINTSIZET"u, "
+
"longer than assumed max %"PRINTSIZET"u.\n",
+
buffer, strlen (buffer), MAX_FLOAT_SPRINTF_LEN);
+
#endif
+
append_buffer: switch(max_shift) { case 0: convert_0_to_0((p_wchar0 *)buf.ptr,buffer,strlen(buffer)); break; case 1: convert_0_to_1((p_wchar1 *)buf.ptr,(p_wchar0 *)buffer, strlen(buffer));