From: Taylor R Campbell Date: Thu, 8 Nov 2018 17:25:14 +0000 (+0000) Subject: Paranoia (and gcc warning suppression): Avoid arithmetic overflow. X-Git-Tag: mit-scheme-pucked-10.1.2~16^2~116^2~2 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=3fafcb40e236d5a702335f4bac5f0aa2f9409f43;p=mit-scheme.git Paranoia (and gcc warning suppression): Avoid arithmetic overflow. --- diff --git a/src/microcode/findprim.c b/src/microcode/findprim.c index f526d261c..f6a117725 100644 --- a/src/microcode/findprim.c +++ b/src/microcode/findprim.c @@ -633,6 +633,11 @@ initialize_token_buffer (void) void grow_token_buffer (void) { + if (token_buffer_length >= (SIZE_MAX / 2)) + { + fprintf (stderr, "token buffer overflow\n"); + exit (1); + } token_buffer_length *= 2; token_buffer = (xrealloc (token_buffer, token_buffer_length)); return; @@ -812,6 +817,11 @@ void grow_data_buffer (void) { char * old_data_buffer = ((char *) data_buffer); + if (buffer_length >= (SIZE_MAX / (2 * (sizeof (struct descriptor))))) + { + fprintf (stderr, "data buffer overflow\n"); + exit (1); + } buffer_length *= 2; data_buffer = ((struct descriptor (*) []) @@ -827,6 +837,11 @@ grow_data_buffer (void) scan += 1; } } + if (buffer_length >= (SIZE_MAX / (sizeof (struct descriptor *)))) + { + fprintf (stderr, "result buffer overflow\n"); + exit (1); + } result_buffer = ((struct descriptor **) (xrealloc (((char *) result_buffer),