[quake3-commits] [ioquake/ioq3] c5b6bb: snd_wavelet: avoid undefined pointer below array b...

Tim Angus tim at ngus.net
Tue Sep 27 16:07:05 EDT 2016


  Branch: refs/heads/master
  Home:   https://github.com/ioquake/ioq3
  Commit: c5b6bb0d4bd8006b89f308021e0bc5450769b590
      https://github.com/ioquake/ioq3/commit/c5b6bb0d4bd8006b89f308021e0bc5450769b590
  Author: Simon McVittie <smcv at debian.org>
  Date:   2016-09-25 (Sun, 25 Sep 2016)

  Changed paths:
    M code/client/snd_wavelet.c

  Log Message:
  -----------
  snd_wavelet: avoid undefined pointer below array bounds

Given an array b[] of length n, pointers to &b[0]..&b[n] are defined
(where only &b[0]..&b[n-1] can be validly dereferenced). &b[-1], or
equivalently b-1, is not something we can use in valid Standard C.

gcc 6 diagnoses this as:

code/client/snd_wavelet.c:33:9: warning: array subscript is below array bounds [-Warray-bounds]

and might take this undefined behaviour as permission to emit
"more efficient" object code that is not what the author expected,
for example nothing at all. Use a macro to fake a 1-based array instead.


  Commit: 01bfb1540f9e6dba72897b5e8cc317aba3e2d036
      https://github.com/ioquake/ioq3/commit/01bfb1540f9e6dba72897b5e8cc317aba3e2d036
  Author: Simon McVittie <smcv at debian.org>
  Date:   2016-09-25 (Sun, 25 Sep 2016)

  Changed paths:
    M code/ui/ui_main.c

  Log Message:
  -----------
  UI_BuildFindPlayerList: avoid array underflow

This function is used in the Team Arena menus

I don't think it's actually possible to reach this line with
foundPlayerServerNames < 1, because by the time we get here we have
set it to 1 + the actual number of servers; but if we did, it would
clearly underflow into foundPlayerServerNames[-1], which would be
undefined behaviour. gcc 6 diagnoses this with a warning:

code/ui/ui_main.c: In function ‘UI_BuildFindPlayerList’:
code/ui/ui_main.c:4138:16: warning: array subscript is below array bounds [-Warray-bounds]

Also correct the sizeof() invocation to make it more obviously
correct (in fact the buffers for names and addresses happen to both
be of size MAX_ADDRESSLENGTH, so it was fine, but it's good to be
obvious).


  Commit: f1a133acf10cab123518e39478875f22b6e91f85
      https://github.com/ioquake/ioq3/commit/f1a133acf10cab123518e39478875f22b6e91f85
  Author: Simon McVittie <smcv at debian.org>
  Date:   2016-09-25 (Sun, 25 Sep 2016)

  Changed paths:
    M code/ui/ui_main.c

  Log Message:
  -----------
  UI_BuildFindPlayerList: make a sizeof() more obviously correct

As with the other branch of the if/else, each element of
foundPlayerServerNames is in fact the same size as each element of
foundPlayerServerAddresses, so it was fine; but it's better to make
it obvious that we are using the right array sizes.


  Commit: f71fe6b61383bf71d72f2f8fb1e9484f41e8cd39
      https://github.com/ioquake/ioq3/commit/f71fe6b61383bf71d72f2f8fb1e9484f41e8cd39
  Author: Tim Angus <tim at ngus.net>
  Date:   2016-09-27 (Tue, 27 Sep 2016)

  Changed paths:
    M code/client/snd_wavelet.c
    M code/ui/ui_main.c

  Log Message:
  -----------
  Merge pull request #226 from smcv/underflow

Fix array underflow compiler warnings


Compare: https://github.com/ioquake/ioq3/compare/cce24668f7c6...f71fe6b61383


More information about the quake3-commits mailing list