On Fri, Feb 25, 2022 at 9:45 AM Hao Wu <wuhao...@google.com> wrote: > I have sent an updated version that uses memcmp() > > On Fri, Feb 25, 2022 at 3:44 AM Peter Maydell <peter.mayd...@linaro.org> > wrote: > >> On Thu, 24 Feb 2022 at 19:03, Hao Wu <wuhao...@google.com> wrote: >> > >> > From: Shengtan Mao <st...@google.com> >> > >> > Reviewed-by: Hao Wu <wuhao...@google.com> >> > Reviewed-by: Chris Rauer <cra...@google.com> >> > Signed-off-by: Shengtan Mao <st...@google.com> >> > Signed-off-by: Patrick Venture <vent...@google.com> >> > Signed-off-by: Hao Wu <wuhao...@google.com> >> > --- >> > v4: >> > * use strncmp to compare fixed length strings >> > v3: >> > * fixup compilation from missing macro value >> > v2: >> > * update copyright year >> > * check result of open >> > * use g_free instead of free >> > * move declarations to the top >> > * use g_file_open_tmp >> > --- >> >> > +static void write_sdread(QTestState *qts, const char *msg) >> > +{ >> > + int fd, ret; >> > + size_t len = strlen(msg); >> > + char *rmsg = g_malloc(len); >> > + >> > + /* write message to sd */ >> > + fd = open(sd_path, O_WRONLY); >> > + g_assert(fd >= 0); >> > + ret = write(fd, msg, len); >> > + close(fd); >> > + g_assert(ret == len); >> > + >> > + /* read message using sdhci */ >> > + ret = sdhci_read_cmd(qts, NPCM7XX_MMC_BA, rmsg, len); >> > + g_assert(ret == len); >> > + g_assert(!strncmp(rmsg, msg, len)); >> >> We always know we want to compare exactly 'len' bytes here, and we know >> the buffers in each case are at least that large. The right function >> for that is memcmp(), I think. >> > Thanks Hao for picking this up :)
> >> thanks >> -- PMM >> >