mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 06:39:17 +02:00
replacing sprintf with snprintf to handle numeric formatting overflow
This commit is contained in:
parent
758e423c1b
commit
aa0af80993
1 changed files with 3 additions and 3 deletions
6
sexp.c
6
sexp.c
|
@ -1132,7 +1132,7 @@ sexp sexp_write_one (sexp ctx, sexp obj, sexp out) {
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
i = sprintf(numbuf, "%.15g", f);
|
i = snprintf(numbuf, 20, "%.15g", f);
|
||||||
if (f == trunc(f) && ! strchr(numbuf, '.')) {
|
if (f == trunc(f) && ! strchr(numbuf, '.')) {
|
||||||
numbuf[i++] = '.'; numbuf[i++] = '0'; numbuf[i++] = '\0';
|
numbuf[i++] = '.'; numbuf[i++] = '0'; numbuf[i++] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -1191,7 +1191,7 @@ sexp sexp_write_one (sexp ctx, sexp obj, sexp out) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (sexp_fixnump(obj)) {
|
} else if (sexp_fixnump(obj)) {
|
||||||
sprintf(numbuf, "%ld", sexp_unbox_fixnum(obj));
|
snprintf(numbuf, 20, "%ld", sexp_unbox_fixnum(obj));
|
||||||
sexp_write_string(ctx, numbuf, out);
|
sexp_write_string(ctx, numbuf, out);
|
||||||
#if SEXP_USE_IMMEDIATE_FLONUMS
|
#if SEXP_USE_IMMEDIATE_FLONUMS
|
||||||
} else if (sexp_flonump(obj)) {
|
} else if (sexp_flonump(obj)) {
|
||||||
|
@ -1203,7 +1203,7 @@ sexp sexp_write_one (sexp ctx, sexp obj, sexp out) {
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
i = sprintf(numbuf, "%.8g", f);
|
i = snprintf(numbuf, 20, "%.8g", f);
|
||||||
if (f == trunc(f) && ! strchr(numbuf, '.')) {
|
if (f == trunc(f) && ! strchr(numbuf, '.')) {
|
||||||
numbuf[i++] = '.'; numbuf[i++] = '0'; numbuf[i++] = '\0';
|
numbuf[i++] = '.'; numbuf[i++] = '0'; numbuf[i++] = '\0';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue