Re: [PATCH v4] string.h: Add str_has_prefix() helper function
From: Steven Rostedt
Date: Sat Dec 22 2018 - 12:47:53 EST
On Sat, 22 Dec 2018 23:24:11 +0900
Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> > No, because we don't know the length of str.
> >
> >
> > [ str = "h\0[bad memory]" ]
> >
> >
> > str_has_prefix(str, "TEST THIS BIG STRING AT FRONT")
> >
> >
> > If we use memcmp(), then we are testing way after str has ended, and
> > that can cause a memory fault.
>
> I don't know what's the bad memory causing memory fault but anyway
> memcpy() should stop at the NUL character first as it's different, no?
No, that's the difference between memcpy() and strncpy(), memcpy()
doesn't care about nul characters. It's copying memory not strings.
-- Steve