Fix gcc/9.3.1 and gcc/10.2.1 errors and warnings

This commit is contained in:
Landon Curt Noll
2021-02-04 17:20:20 -08:00
parent 8b7e01f426
commit 71a116ca6f
5 changed files with 123 additions and 25 deletions

23
file.c
View File

@@ -50,6 +50,8 @@
#define READSIZE 1024 /* buffer size for reading */
#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
/*
* external STDIO functions
*/
@@ -1414,23 +1416,21 @@ z2filepos(ZVALUE zpos)
#if FILEPOS_BITS == FULL_BITS
/* ztofull puts the value into native byte order */
pos = ztofull(zpos);
/* on some hosts, FILEPOS is not a scalar */
memset(&ret, 0, sizeof(FILEPOS));
memcpy((void *)&ret, (void *)&pos, sizeof(FILEPOS));
memset(&ret, 0, sizeof(ret)); /* on some hosts, FILEPOS is not a scalar */
memcpy((void *)&ret, (void *)&pos, MIN(sizeof(ret), sizeof(pos)));
return ret;
#elif FILEPOS_BITS < FULL_BITS
/* ztofull puts the value into native byte order */
pos = ztolong(zpos);
/* on some hosts, FILEPOS is not a scalar */
memset(&ret, 0, sizeof(FILEPOS));
memcpy((void *)&ret, (void *)&pos, sizeof(pos));
memset(&ret, 0, sizeof(ret)); /* on some hosts, FILEPOS is not a scalar */
memcpy((void *)&ret, (void *)&pos, MIN(sizeof(ret), sizeof(pos)));
return ret;
#else /* FILEPOS_BITS > FULL_BITS */
if (!zgtmaxfull(zpos)) {
/* ztofull puts the value into native byte order */
pos = ztofull(zpos);
memset(&ret, 0, sizeof(FILEPOS));
memcpy((void *)&ret, (void *)&pos, sizeof(pos));
memset(&ret, 0, sizeof(ret)); /* on some hosts, FILEPOS is not a scalar */
memcpy((void *)&ret, (void *)&pos, MIN(sizeof(ret), sizeof(pos)));
return ret;
}
@@ -1439,11 +1439,12 @@ z2filepos(ZVALUE zpos)
*/
if (zpos.len >= FILEPOS_BITS/BASEB) {
/* copy the lower FILEPOS_BITS of the ZVALUE */
memcpy(&tmp, zpos.v, sizeof(FILEPOS));
memset(&tmp, 0, sizeof(tmp)); /* on some hosts, FILEPOS is not a scalar */
memcpy(&tmp, zpos.v, MIN(sizeof(tmp), FILEPOS_LEN);
} else {
/* copy what bits we can into the temp value */
memset(&tmp, 0, sizeof(FILEPOS));
memcpy(&tmp, zpos.v, zpos.len*BASEB/8);
memset(&tmp, 0, sizeof(tmp)); /* on some hosts, FILEPOS is not a scalar */
memcpy(&tmp, zpos.v, MIN(sizeof(tmp), MIN(zpos.len*BASEB/8, FILEPOS_LEN)));
}
/* swap into native byte order */
SWAP_HALF_IN_FILEPOS(&ret, &tmp);