diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-08-10 19:36:16 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-08-11 11:33:15 +0200 |
| commit | 143b4d3f64e0828a3b03dd9ed997dd5412c2b25a (patch) | |
| tree | 35eafecc76d4cf06aa6017db14e7124774889dae /src/projects.h | |
| parent | 7b7e69690d13bd5d6b6468c6a11a81f871bd7127 (diff) | |
| download | PROJ-143b4d3f64e0828a3b03dd9ed997dd5412c2b25a.tar.gz PROJ-143b4d3f64e0828a3b03dd9ed997dd5412c2b25a.zip | |
Fix wrong behaviour of torad_coord() with gcc 8.1 -O2 (fixes #1084)
torad_coord() of gie.c has this sequence:
```
if( cond )
axis = l->param + strlen ("axis=");
n = strlen (axis);
```
When the if branch is evaluated, n is always zero
even if on inspection axis is non empty
The reason is that the struct ARG_list which is the
type of l use a variable-length array for the param member
struct ARG_list {
paralist *next;
char used;
char param[1];
};
But this is not a proper way of declaring it, and
gcc 8 has apparently optimizations to detect that l->param + 5
points out of the array, hence it optimizes strlen() to 0.
Reported as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914
According to https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html,
the proper way of declaring such arrays is to use [0]
Diffstat (limited to 'src/projects.h')
| -rw-r--r-- | src/projects.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/projects.h b/src/projects.h index 2dc073fa..928985f6 100644 --- a/src/projects.h +++ b/src/projects.h @@ -458,7 +458,12 @@ struct PJconsts { struct ARG_list { paralist *next; char used; - char param[1]; +#ifdef __GNUC__ + char param[0]; /* variable-length member */ + /* Safer to use [0] for gcc. See https://github.com/OSGeo/proj.4/pull/1087 */ +#else + char param[1]; /* variable-length member */ +#endif }; |
