codeplea / tinyexpr

tiny recursive descent expression parser, compiler, and evaluation engine for math expressions
https://codeplea.com/tinyexpr
zlib License
1.61k stars 245 forks source link

array bounds warning with gcc-11 #87

Open roblatham00 opened 3 years ago

roblatham00 commented 3 years ago

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"

KonstiDE commented 3 months ago

PR #88 solves it, thanks @roblatham00