I wish that there was something funny I could say about C-style, null-terminated strings. There isn't. "Putting a sentinel value at the end of a variable length sequence instead of a fixed-size count at the beginning: priceless." The fact is, they just aren't funny.


Maybe that's why Sergey wasn't laughing when he found the following code lurking deep within his source repository.


  key_p = &buf[buf_i];
key_len = strlen(key_p);
 
printf("key_len<%d>\n", key_len);
if (key_p[key_len] != 0x00)
{
fprintf(stderr, "key termination error %02x\n",
key_p[key_len]);
close(key_fd);
return;
  }
if (debug) {
  printf("len<%d> key<%s>\n", key_len, key_p);
}

 

I guess if you've got a broken standard library (or a broken understanding thereof) the code may be of some use. It just makes me wonder how the original programmer thinks strlen works.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!