[postgis-commits] svn - r3375 - in trunk: liblwgeom lwgeom
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Thu Dec 11 05:46:30 PST 2008
Author: mcayland
Date: 2008-12-11 05:46:29 -0800 (Thu, 11 Dec 2008)
New Revision: 3375
Modified:
trunk/liblwgeom/lwutil.c
trunk/lwgeom/lwgeom_pg.c
Log:
Fix up a couple of errors in the new lwmessage_truncate() function found by Kevin - correct an off-by-one error in the code, and include a missing startpos offset in the end truncation code. Also ensure that if maxlength gets too small then we return "..." rather than crashing.
Modified: trunk/liblwgeom/lwutil.c
===================================================================
--- trunk/liblwgeom/lwutil.c 2008-12-10 12:36:28 UTC (rev 3374)
+++ trunk/liblwgeom/lwutil.c 2008-12-11 13:46:29 UTC (rev 3375)
@@ -274,8 +274,9 @@
/*
* Returns a new string which contains a maximum of maxlength characters starting
- * from startpos and finishing at endpos. If the string is truncated then the
- * first or last characters are replaced by "..." as appropriate.
+ * from startpos and finishing at endpos (0-based indexing). If the string is
+ * truncated then the first or last characters are replaced by "..." as
+ * appropriate.
*
* The caller should specify start or end truncation by setting the truncdirection
* parameter as follows:
@@ -296,17 +297,25 @@
if (truncdirection == 0)
{
/* Calculate the start position */
- if (endpos - startpos <= maxlength)
+ if (endpos - startpos < maxlength)
{
outstart = str + startpos;
- strncat(output, outstart, endpos - startpos);
+ strncat(output, outstart, endpos - startpos + 1);
}
else
{
- /* Add "..." prefix */
- outstart = str + endpos - maxlength + 3;
- strncpy(output, "...", 4);
- strncat(output, outstart, maxlength - 3);
+ if (maxlength >= 3)
+ {
+ /* Add "..." prefix */
+ outstart = str + endpos + 1 - maxlength + 3;
+ strncat(output, "...", 3);
+ strncat(output, outstart, maxlength - 3);
+ }
+ else
+ {
+ /* maxlength is too small; just output "..." */
+ strncat(output, "...", 3);
+ }
}
}
@@ -314,15 +323,25 @@
if (truncdirection == 1)
{
/* Calculate the end position */
- if (endpos - startpos <= maxlength)
+ if (endpos - startpos < maxlength)
{
- strncat(output, str, endpos - startpos);
+ outstart = str + startpos;
+ strncat(output, outstart, endpos - startpos + 1);
}
else
{
- /* Add "..." suffix */
- strncat(output, str, maxlength - 3);
- strncat(output, "...", 3);
+ if (maxlength >= 3)
+ {
+ /* Add "..." suffix */
+ outstart = str + startpos;
+ strncat(output, outstart, maxlength - 3);
+ strncat(output, "...", 3);
+ }
+ else
+ {
+ /* maxlength is too small; just output "..." */
+ strncat(output, "...", 3);
+ }
}
}
Modified: trunk/lwgeom/lwgeom_pg.c
===================================================================
--- trunk/lwgeom/lwgeom_pg.c 2008-12-10 12:36:28 UTC (rev 3374)
+++ trunk/lwgeom/lwgeom_pg.c 2008-12-11 13:46:29 UTC (rev 3375)
@@ -32,7 +32,7 @@
char *hintbuffer;
/* Return a copy of the input string start truncated at the error location */
- hintbuffer = lwmessage_truncate((char *)lwg_parser_result->wkinput, 0, lwg_parser_result->errlocation, 40, 0);
+ hintbuffer = lwmessage_truncate((char *)lwg_parser_result->wkinput, 0, lwg_parser_result->errlocation - 1, 40, 0);
/* Only display the parser position if the location is > 0; this provides a nicer output when the first token
within the input stream cannot be matched */
More information about the postgis-commits
mailing list