codeplea/tinyexpr

array bounds warning with gcc-11

roblatham00 opened this issue · 1 comments

When I build tinyexpr with gcc-11 I get warnings about array subscripts exceeding bounds:

%   gcc --version
gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0
gcc -Wall -Wshadow -O2 -o smoke smoke.c tinyexpr.c -lm
tinyexpr.c: In function ‘base’:
tinyexpr.c:321:16: warning: array subscript ‘te_expr[0]’ is partly outside array bounds of ‘unsigned char[16]’ [-Warray-bounds]
  321 |             ret->bound = s->bound;
      |                ^~
tinyexpr.c:90:20: note: referencing an object of size 16 allocated by ‘malloc’
   90 |     te_expr *ret = malloc(size);
      |                    ^~~~~~~~~~~~

Reproducing is easy: I checked out tinyexpr from github and typed "make"

PR #88 solves it, thanks @roblatham00