Patch from Scott McKellar to correct some problems with _jsonParserError(),
which constructs and issues a message about a parsing error:
The problems arise in the course of extracting a fragment of JSON text to
provide the context of the error.
1. The code starts by picking the beginning and end of the fragment to
extract. In order to avoid beginning before the start of the string,
the original code goes through a loop, incrementing an index until it
is non-negative. A similar loop corrects for an ending beyond the
end of the string.
These loops do the job, but to my eyes they look silly. I replaced
them by assigning the corrected values directly, when corrections
are in order.
2. There is an off-by-two error in calculating the size of the buffer
needed to hold the fragment. To begin with, we miscalculate the
length of the fragment. If the fragment extends from character 30
through character 40, there are 11 characters in the fragment, not
10. Then we neglect to add another byte for a terminal nul.
The result is that the last two characters in the intended fragment
are not displayed. If the character in error is the last or the
next to last character in the string, it doesn't get displayed as
part of the fragment, leading to likely bafflement.
I corrected both these errors, embiggening the buffer by two.
3. The original code copies the fragment into the buffer by calling
snprintf(). Besides being needlessly inefficient, snprintf() is
dangerous in this context. If the copied fragment contains a
format specifier such as "%s" or "%d", sprintf goes off looking for
a non-existent parameter, resulting in a mangled message or worse.
I replaced the snprintf() with a memcpy() and a terminal nul.
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1165
9efc2488-bf62-4759-914b-
345cdb29e865