2
0
mirror of https://github.com/Unidata/netcdf-c.git synced 2025-02-23 16:59:54 +08:00

Fix type punning in val_NC_check_voff() by using memcpy instead of assignment

gcc11 explicitly warns about this strict aliasing violation:
daux.c:903:30: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   903 |         params[nparams++] = *(unsigned int*)&valf;
       |
       |                              ^~~~~~~~~~~~~~~~~~~~

Signed-off-by: Egbert Eich <eich@suse.com>
This commit is contained in:
Egbert Eich 2021-07-12 09:58:28 +02:00
parent 269ff33844
commit fbad04ee79

View File

@ -900,7 +900,8 @@ filterspec_cvt(const char* txt, size_t* nparamsp, unsigned int* params)
sstat = sscanf(p,"%lf",&vald);
if(sstat != 1) {stat = NC_EINVAL; goto done;}
valf = (float)vald;
params[nparams++] = *(unsigned int*)&valf;
/* avoid type punning */
memcpy(&params[nparams++], &valf, sizeof(unsigned int));
break;
/* The following are 8-byte values, so we must swap pieces if this
is a little endian machine */