<div dir="ltr"><div class="gmail_quote">On Thu, Jan 26, 2012 at 09:10, Michael Müller <span dir="ltr"><<a href="mailto:mueller_michael@alice-dsl.net">mueller_michael@alice-dsl.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><br><div><div>Am 26.01.2012 um 03:50 schrieb ik:</div><div class="im"><br><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" target="_blank">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" target="_blank">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><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></div></div></blockquote><div><br><br>Thanks, <br>I used valgrind and discovered this: <br>
==20532== at 0x458754: RD_TYPES_TREDISMULTIBULKRETURNTYPE_$__INSERT$LONGINT$TREDISRETURNTYPE (rd_types.pas:406)<br><br>It was off by one else where. Why does it take such time to effect the executable ?<br><br><br> </div>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div><div><br></div><div>Regards</div><span class="HOEnZb"><font color="#888888"><div>
<br></div><div>Michael</div></font></span></div></div></div></blockquote><div><br>Ido <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br></blockquote></div><br></div>