<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>Am 26.01.2012 um 03:50 schrieb ik:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hello,<br><br>While testing my following code:<br><a href="https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L166">https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L166</a><br>
<br>When I'm executing the code on the second item (that is suppose to be null in the protocol -> '$-1#13#10'),<br>the program crashes with the following message:<br>*** glibc detected *** redis_client/tests/test_parser: malloc(): memory corruption (fast): 0x0000000000750d50 ***<br>
<br>Using gdb to display the information seems that the following like:<br><a href="https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L85">https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L85</a> is the cause.<br>
It looks like accessing either tmps or ALine[j] is causing it.<br></div></blockquote><div><br></div><div>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.</div><div>So change</div><div>while (ALine[j] <> #13) and (j <= alength) do</div><div>into</div><div><div>while (j <= alength) and (ALine[j] <> #13) do</div><div><br></div><div>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.</div><div>If you can't ensure that you should do it like this</div><div><div>while (j <= alength) do</div><div> if (ALine[j] <> #13) then</div></div><div><br></div><div>Regards</div><div><br></div><div>Michael</div></div></div></body></html>