[postgis-devel] Re: [postgis-users] how to identify the_geom that cause : RelateOperation called withLWGEOMCOLLECTION type
Mark Cave-Ayland
mark.cave-ayland at siriusit.co.uk
Thu Dec 11 05:55:11 PST 2008
Kevin Neufeld wrote:
> Yup, that's makes sense ... it's similar to what I have in
> errorIfGeometryCollection.
>
> Doing a little testing, however, I'm not clear on what you were
> expecting to see based on certain inputs - my expected results don't
> match the function output. I put the function in a little test.c file
> to test the method where:
>
>
> char* str = "abcdefghijklmnopqrstuvwxyz";
>
> // Assuming 0-based indexing
> lwmessage_truncate(str, 0, strlen(str)-1, 26, 0);
> expected: "abcdefghijklmnopqrstuvwxyz"
> output: "abcdefghijklmnopqrstuvwxy"
>
> lwmessage_truncate(str, 0, strlen(str)-1, 26, 1);
> expected: "abcdefghijklmnopqrstuvwxyz"
> output: "abcdefghijklmnopqrstuvwxy"
>
> lwmessage_truncate(str, 0, strlen(str)-1, 25, 0);
> expected: "...efghijklmnopqrstuvwxyz"
> output: "abcdefghijklmnopqrstuvwxy"
>
> lwmessage_truncate(str, 0, strlen(str)-1, 25, 1);
> expected: "abcdefghijklmnopqrstuv..."
> output: "abcdefghijklmnopqrstuvwxy"
These we caused by an off-by-one error in the code, as in the original
commit endpos was actually 1-based indexed, rather than 0-based like
startpos :(
> lwmessage_truncate(str, 2, strlen(str)-1, 10, 1);
> expected: "cdefghi..."
> output: "abcdefg..."
>
> lwmessage_truncate(str, 4, strlen(str)-1, 10, 1);
> expected: "efghijk..."
> output: "abcdefg..."
Ahhh. Forgot to add the startpos offset when performing start truncation...
> lwmessage_truncate(str, 0, strlen(str)-1, 10, 0);
> expected: "...tuvwxyz"
> output: "...stuvwxy"
>
> lwmessage_truncate(str, 0, strlen(str)-3, 10, 0);
> expected: "...rstuvwx"
> output: "...qrstuvw"
>
> lwmessage_truncate(str, 0, strlen(str)-5, 10, 0);
> expected: "...pqrstuv"
> output: "...opqrstu"
These are again a symptom of the off-by-one error.
> lwmessage_truncate(str, 0, strlen(str)-1, 4, 1);
> expected: "a..."
> output: "a..."
>
> lwmessage_truncate(str, 0, strlen(str)-1, 3, 1);
> expected: "a.."
> output: "..."
>
> lwmessage_truncate(str, 0, strlen(str)-1, 2, 1);
> expected: "a."
> output: "abcdefghijklmnopqrstuvwxyz..."
> *** glibc detected *** free(): invalid next size (fast): 0x08b88028 ***
> Aborted
These really lie in the category of "don't do that", but they shouldn't
invoke a crash. For the moment, anything that is truncated where
maxlength is < 3 will simply return a fixed "..." string.
> Am I using it correctly?
Yes, of course. Fixes for all of the above have been committed to SVN -
thanks for testing :)
ATB,
Mark.
--
Mark Cave-Ayland
Sirius Corporation - The Open Source Experts
http://www.siriusit.co.uk
T: +44 870 608 0063
More information about the postgis-devel
mailing list