Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-12

AnsiStrLComp AnsiStrLIComp

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner

Hi,

According to the docs AnsiStrLComp treats #0 as normal characters, which sounds as if it does not stop at #0.
Does it stop at #0 or does it not?
http://www.freepascal.org/docs-html/rtl/sysutils/ansistrlcomp.html

The doc of AnsiStrLIComp says "compares the first MaxLen characters", which sounds as if it does not stop at #0.
OTOH the examples seems to stop at #0.
Does it stop at #0 or does it not?
http://www.freepascal.org/docs-html/rtl/sysutils/ansistrlicomp.html

The docs of AnsiStrComp and AnsiStrIComp clearly state they stop at #0.

Mattias

Reply by email

Jonas Maebe
to Mattias Gaertner
Mattias Gaertner wrote 10 lines
According to the docs AnsiStrLComp treats #0 as normal characters, which sounds as if it does not stop at #0. Does it stop at #0 or does it not? http://www.freepascal.org/docs-html/rtl/sysutils/ansistrlcomp.html The doc of AnsiStrLIComp says "compares the first MaxLen characters", which sounds as if it does not stop at #0. OTOH the examples seems to stop at #0. Does it stop at #0 or does it not? http://www.freepascal.org/docs-html/rtl/sysutils/ansistrlicomp.html

Neither of these routines stops at #0.

Jonas

Reply by email

Mattias Gaertner
to Jonas Maebe
Show quoted text 15 lines
On 04 Dec 2014, at 16:24, Mattias Gaertner wrote: > According to the docs AnsiStrLComp treats #0 as normal characters, > which sounds as if it does not stop at #0. > Does it stop at #0 or does it not? > http://www.freepascal.org/docs-html/rtl/sysutils/ansistrlcomp.html > > The doc of AnsiStrLIComp says "compares the first MaxLen characters", > which sounds as if it does not stop at #0. > OTOH the examples seems to stop at #0. > Does it stop at #0 or does it not? > http://www.freepascal.org/docs-html/rtl/sysutils/ansistrlicomp.html Neither of these routines stops at #0.

Thanks.

Michael, can you add a comment to this example, that runs beyond the strings:
Testit('One string','One smaller string',255);

Mattias

Reply by email

Michael Van Canneyt
to Mattias Gaertner
Mattias Gaertner wrote 24 lines
On Mon, 8 Dec 2014 13:22:42 +0100 Jonas Maebe wrote: > > On 04 Dec 2014, at 16:24, Mattias Gaertner wrote: > >> According to the docs AnsiStrLComp treats #0 as normal characters, >> which sounds as if it does not stop at #0. >> Does it stop at #0 or does it not? >> http://www.freepascal.org/docs-html/rtl/sysutils/ansistrlcomp.html >> >> The doc of AnsiStrLIComp says "compares the first MaxLen characters", >> which sounds as if it does not stop at #0. >> OTOH the examples seems to stop at #0. >> Does it stop at #0 or does it not? >> http://www.freepascal.org/docs-html/rtl/sysutils/ansistrlicomp.html > > Neither of these routines stops at #0. Thanks. Michael, can you add a comment to this example, that runs beyond the strings: Testit('One string','One smaller string',255);

? There is no #0 character. So what does this example prove ?

Michael.

Reply by email

Mattias Gaertner
to Michael Van Canneyt
Show quoted text 6 lines
[...] > Michael, can you add a comment to this example, that runs beyond the > strings: > Testit('One string','One smaller string',255); ? There is no #0 character. So what does this example prove ?

I'm not sure if every reader knows why this example works. The number should be lower or equal the length of the shortest string to avoid running out of bounds.
The 255 looks as if it is ok to pass a number bigger than the length of the strings.

For example this creates an AV on x86_64:
AnsiStrLIComp('A','B',1000000);

Mattias

Reply by email