Commit 2182c818 authored by Raúl Marín's avatar Raúl Marín

Fix undefined behaviour in SADFWrite

Also addresses several GCC warnings.

Closes #4189
Closes https://github.com/postgis/postgis/pull/310


git-svn-id: http://svn.osgeo.org/postgis/trunk@16863 b70326c6-7e19-0410-871a-916f4a2858ee
parent 567ba507
Pipeline #31763436 passed with stage
in 23 minutes and 23 seconds
......@@ -21,6 +21,7 @@ PostGIS 3.0.0
- #4181, St_AsMVTGeom: Avoid type changes due to validation (Raúl Marín)
- #4183, St_AsMVTGeom: Drop invalid geometries after simplification (Raúl Marín)
- #4188, Avoid division by zero in kmeans (Raúl Marín)
- #4189, Fix undefined behaviour in SADFWrite (Raúl Marín)
PostGIS 2.5.0
2018/09/23
......
......@@ -280,13 +280,13 @@ char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int
{
/* Add "..." prefix */
outstart = str + endpos + 1 - maxlength + 3;
strncat(output, "...", 3);
strncat(output, "...", 4);
strncat(output, outstart, maxlength - 3);
}
else
{
/* maxlength is too small; just output "..." */
strncat(output, "...", 3);
strncat(output, "...", 4);
}
}
}
......@@ -307,12 +307,12 @@ char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int
/* Add "..." suffix */
outstart = str + startpos;
strncat(output, outstart, maxlength - 3);
strncat(output, "...", 3);
strncat(output, "...", 4);
}
else
{
/* maxlength is too small; just output "..." */
strncat(output, "...", 3);
strncat(output, "...", 4);
}
}
}
......
......@@ -1549,7 +1549,7 @@ ShpDumperOpenTable(SHPDUMPERSTATE *state)
{
if (!strncasecmp(dbffieldname, state->dbffieldnames[j], 10))
{
sprintf(dbffieldname, "%.7s_%.2d", ptr, tmpint % 100);
sprintf(dbffieldname, "%.7s_%.2d", ptr, abs(tmpint) % 100);
tmpint++;
continue;
}
......
......@@ -115,8 +115,9 @@ SAOffset SADFRead( void *p, SAOffset size, SAOffset nmemb, SAFile file )
SAOffset SADFWrite( void *p, SAOffset size, SAOffset nmemb, SAFile file )
{
return (SAOffset) fwrite( p, (size_t) size, (size_t) nmemb,
(FILE *) file );
if (!nmemb || !p) return 0;
return (SAOffset) fwrite( p, (size_t) size, (size_t) nmemb,
(FILE *) file );
}
/************************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment