79788693

Date: 2025-10-12 17:50:08
Score: 1
Natty:
Report link

I understand your question is multi-layered, and the run-time crashing of your custom strlen() is nearly a side note, but I thought I'd address just this one aspect nonetheless. Does your code care for the possibility of a NULL parameter as does the following custom strlen()?

Runnable code here: https://godbolt.org/z/xofh9sYqK

#include <stdio.h>   /* printf()  */

size_t mstrlen( const char *str )
{
    size_t len = 0;

    if( str )  /* Prevent run-time crash on NULL pointer. */
    {
        for(; str[len]; len++);
    }
    return len;
}


int main()
{

    char s[] = "stars";

    printf("mstrlen(%s) = %llu\n", s, mstrlen(s));
    printf("mstrlen(NULL) = %llu\n",  mstrlen(NULL));

    return 0;
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
Posted by: greg spears