Am 26.01.2012 um 03:50 schrieb ik:

> Hello,
> 
> While testing my following code:
> https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L166
> 
> When I'm executing the code on the second item (that is suppose to be null in 
> the protocol -> '$-1#13#10'),
> the program crashes with the following message:
> *** glibc detected *** redis_client/tests/test_parser: malloc(): memory 
> corruption (fast): 0x0000000000750d50 ***
> 
> Using gdb to display the information seems that the following like:
> https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L85 
> is the cause.
> It looks like accessing either tmps or ALine[j] is causing it.

I would expect that already line 83 is the problem. You have to change the 
order of the statements otherwise you'll access a not existing element in ALine 
before checking if the index is already to big when j becomes > alength.
So change
while (ALine[j] <> #13) and (j <= alength) do
into
while (j <= alength) and (ALine[j] <> #13) do

But this will only work if the compiler switch {$B-} (verbose version 
{$BOOLEVAL OFF}) is set which is the default in Delphi so I assume the same in 
FPC too.
If you can't ensure that you should do it like this
while (j <= alength) do
  if (ALine[j] <> #13) then

Regards

Michael
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to