News for hackers. Stuff that matters.
Re:Sentinels Can Be Faster by klodolph on Wednesday September 09, 2020 @08:13PM (#24427514)
I think you may have misinterpreted the code.

> Zero spaces is a number of leading spaces. If you feed his efficient solution a string without a leading space, it'll read past the end of the string and into undefined memory until the program either crashes or reads some arbitrary space character (0x20) from some other string. If it contains spaces but doesn't start with one, you'll think it has more leading spaces than it actually does.

I don't know what code you are referring to, but I'm looking at this code:

    const char * skip_leading_spaces(const char * start) {
      while(is_space(*start)) {
        start++;
      }
      return start;
    }
And this correctly handles the case with zero leading spaces. It correctly handles empty strings.

Recall that is_space('\0') is false (or at least isspace('\0') is false). Also recall that it is valid to read the \0 byte at the end of a string.

I find it a bit unusual that you are capitalizing NULL. My interpretation is that you are talking about the byte '\0', which is also called the null byte, and not the NULL pointer.

There are no comments on this comment yet.