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

Fix undefined behaviour in SADFWrite

Also addresses several gcc warnings
References #4189


git-svn-id: http://svn.osgeo.org/postgis/branches/2.5@16862 b70326c6-7e19-0410-871a-916f4a2858ee
parent c945946c
Pipeline #31763282 (#2798) passed with stage
in 23 minutes
......@@ -4,6 +4,7 @@ XXXX/XX/XX
* Bug fixes *
- #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
......
......@@ -282,13 +282,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);
}
}
}
......@@ -309,12 +309,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