Page MenuHomeFreeBSD

Do not depend on stdin.
ClosedPublic

Authored by oshogbo on Nov 18 2018, 3:07 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, May 6, 11:57 AM
Unknown Object (File)
Sat, Apr 20, 3:21 AM
Unknown Object (File)
Feb 20 2024, 10:44 PM
Unknown Object (File)
Feb 9 2024, 2:58 AM
Unknown Object (File)
Dec 25 2023, 9:59 PM
Unknown Object (File)
Dec 25 2023, 9:59 PM
Unknown Object (File)
Dec 25 2023, 9:59 PM
Unknown Object (File)
Dec 24 2023, 12:14 PM

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

cem accepted this revision.EditedNov 18 2018, 11:30 PM

I like the change. All of my comments below describe existing issues in the code, nothing you introduced in this change. Maybe they can be addressed separately.

contrib/elftoolchain/strings/strings.c
249–251

I think this check can be removed.

254

This memset is unnecessary

298

This return type is bogus on 32-bit arch (sizeof(long) == 4).

EOF (-1) is indistinguishable from a valid 32-bit value.

306–310

Isn't this bogus? It will spuriously fail to read the last byte at the end of the file. It also mishandles stream errors prior to EOF.

I suggest:

c = getc(pfile);
if (c == EOF)
    return (EOF);

instead.

325–330

This math is undefined behavior on 32-bit long systems, I think (left shift into sign bit).

Probably the "value" result should be a 32-bit unsigned integer.

And the return type can either be a wider signed type (int64_t) or the error status can be separated from the return value (i.e., uint32_t *value output parameter).

365

I don't think there's any reason to keep this conditional on feof(pfile). EOF could also indicate an IO error rather than actual end of file. We don't want to continue if getcharacter() returned EOF regardless of anything else.

412–417

EOF check should be done before (uint8_t)c > 127 test, which for c == EOF will always succeed.

This revision is now accepted and ready to land.Nov 18 2018, 11:30 PM

I like this change.

Adding @kaiw and @jkoshy_users.sourceforge.net to CC as a heads-up as we will want this to go upstream as well. (I can take care of the upstream commit.)

contrib/elftoolchain/strings/strings.c
249–251

Thanks. You are right I will address that.

254

Thanks. You are right I will address that.

298

Thanks. You are right I will fix that as separate commit.

306–310

Thanks. You are right I will fix that as separate commit.

325–330

Thanks. You are right I will fix that as separate commit.

365

Thanks. You are right I will fix that as separate commit.

412–417

Thanks. You are right I will fix that as separate commit.

This revision was automatically updated to reflect the committed changes.