mirror of
https://github.com/uffejakobsen/acme.git
synced 2024-11-25 23:49:25 +00:00
fixed buffer overrun when printing long ints on 64bit machines
git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@256 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
parent
1441da12ac
commit
9f5ac5b212
@ -547,8 +547,7 @@ static const char *long_option(const char *string)
|
|||||||
else if (strcmp(string, OPTION_DIALECT) == 0)
|
else if (strcmp(string, OPTION_DIALECT) == 0)
|
||||||
set_dialect(cliargs_get_next()); // NULL is ok (handled like unknown)
|
set_dialect(cliargs_get_next()); // NULL is ok (handled like unknown)
|
||||||
else if (strcmp(string, OPTION_TEST) == 0) {
|
else if (strcmp(string, OPTION_TEST) == 0) {
|
||||||
if (config.test_new_features)
|
config.wanted_version = VER_FUTURE;
|
||||||
config.wanted_version = VER_FUTURE; // giving "--test" twice enables every new feature
|
|
||||||
config.test_new_features = TRUE;
|
config.test_new_features = TRUE;
|
||||||
} PLATFORM_LONGOPTION_CODE
|
} PLATFORM_LONGOPTION_CODE
|
||||||
else if (strcmp(string, OPTION_COLOR) == 0)
|
else if (strcmp(string, OPTION_COLOR) == 0)
|
||||||
|
11
src/alu.c
11
src/alu.c
@ -2265,14 +2265,19 @@ static void object_no_op(struct object *self)
|
|||||||
|
|
||||||
// int/float:
|
// int/float:
|
||||||
// print value for user message
|
// print value for user message
|
||||||
|
#define NUMBUFSIZE 64 // large enough(tm) even for 64bit systems
|
||||||
static void number_print(const struct object *self, struct dynabuf *db)
|
static void number_print(const struct object *self, struct dynabuf *db)
|
||||||
{
|
{
|
||||||
char buffer[40]; // large enough(tm)
|
char buffer[NUMBUFSIZE];
|
||||||
|
|
||||||
if (self->u.number.ntype == NUMTYPE_UNDEFINED) {
|
if (self->u.number.ntype == NUMTYPE_UNDEFINED) {
|
||||||
DynaBuf_add_string(db, "<UNDEFINED NUMBER>");
|
DynaBuf_add_string(db, "<UNDEFINED NUMBER>");
|
||||||
} else if (self->u.number.ntype == NUMTYPE_INT) {
|
} else if (self->u.number.ntype == NUMTYPE_INT) {
|
||||||
|
#if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
|
||||||
|
snprintf(buffer, NUMBUFSIZE, "%ld (0x%lx)", (long) self->u.number.val.intval, (long) self->u.number.val.intval);
|
||||||
|
#else
|
||||||
sprintf(buffer, "%ld (0x%lx)", (long) self->u.number.val.intval, (long) self->u.number.val.intval);
|
sprintf(buffer, "%ld (0x%lx)", (long) self->u.number.val.intval, (long) self->u.number.val.intval);
|
||||||
|
#endif
|
||||||
DynaBuf_add_string(db, buffer);
|
DynaBuf_add_string(db, buffer);
|
||||||
} else if (self->u.number.ntype == NUMTYPE_FLOAT) {
|
} else if (self->u.number.ntype == NUMTYPE_FLOAT) {
|
||||||
// write up to 30 significant characters.
|
// write up to 30 significant characters.
|
||||||
@ -2492,6 +2497,7 @@ void ALU_defined_int(struct number *intresult) // no ACCEPT constants?
|
|||||||
if (expression.result.type == &type_number) {
|
if (expression.result.type == &type_number) {
|
||||||
if (expression.result.u.number.ntype == NUMTYPE_UNDEFINED) {
|
if (expression.result.u.number.ntype == NUMTYPE_UNDEFINED) {
|
||||||
Throw_serious_error("Value not defined.");
|
Throw_serious_error("Value not defined.");
|
||||||
|
expression.result.u.number.val.intval = 0;
|
||||||
} else if (expression.result.u.number.ntype == NUMTYPE_INT) {
|
} else if (expression.result.u.number.ntype == NUMTYPE_INT) {
|
||||||
// ok
|
// ok
|
||||||
} else if (expression.result.u.number.ntype == NUMTYPE_FLOAT) {
|
} else if (expression.result.u.number.ntype == NUMTYPE_FLOAT) {
|
||||||
@ -2530,7 +2536,8 @@ void ALU_addrmode_int(struct expression *expression, int paren) // ACCEPT_UNDEFI
|
|||||||
// convert float to int
|
// convert float to int
|
||||||
if (expression->result.u.number.ntype == NUMTYPE_FLOAT)
|
if (expression->result.u.number.ntype == NUMTYPE_FLOAT)
|
||||||
float_to_int(&(expression->result));
|
float_to_int(&(expression->result));
|
||||||
// FIXME - check for undefined?
|
else if (expression->result.u.number.ntype == NUMTYPE_UNDEFINED)
|
||||||
|
expression->result.u.number.val.intval = 0;
|
||||||
} else if (expression->result.type == &type_string) {
|
} else if (expression->result.type == &type_string) {
|
||||||
// accept single-char strings, to be more
|
// accept single-char strings, to be more
|
||||||
// compatible with versions before 0.97:
|
// compatible with versions before 0.97:
|
||||||
|
@ -60,7 +60,7 @@ static void dump_one_symbol(struct rwnode *node, FILE *fd)
|
|||||||
else if (symbol->object.u.number.ntype == NUMTYPE_FLOAT)
|
else if (symbol->object.u.number.ntype == NUMTYPE_FLOAT)
|
||||||
fprintf(fd, "%.30f", symbol->object.u.number.val.fpval); //FIXME %g
|
fprintf(fd, "%.30f", symbol->object.u.number.val.fpval); //FIXME %g
|
||||||
else
|
else
|
||||||
Bug_found("BogusType", 0); // FIXME - put in docs!
|
Bug_found("IllegalNumberType4", symbol->object.u.number.ntype);
|
||||||
if (symbol->object.u.number.flags & NUMBER_EVER_UNDEFINED)
|
if (symbol->object.u.number.flags & NUMBER_EVER_UNDEFINED)
|
||||||
fprintf(fd, "\t; ?"); // TODO - write "forward" instead?
|
fprintf(fd, "\t; ?"); // TODO - write "forward" instead?
|
||||||
if (!symbol->has_been_read)
|
if (!symbol->has_been_read)
|
||||||
|
Loading…
Reference in New Issue
Block a user