Search code examples
cmailslot

Expression: (L "String is not null terminated" & & 0)


I am fiddling around with mailslots and now I've run into a problem. Whenever I try to run, I get the error message in the title, but I don't know how I should go about fixing it. What I am trying to do is "fixing" the full path of the mailslot, but it seems to not like the strcat_s-part.

HANDLE mailslotCreate (char *name) {
    char fullName[50] = "\\\\.\\mailslot\\";
    strcat_s(fullName, strlen(fullName), name);
    return CreateMailslot(fullName, 0, TIME_OUT, NULL);
}

Imgur link to error

EDIT: Changing the strlen to sizeof merely changed the error to "Buffer size too small" instead.


Solution

  • See documentation on strcat_s. It says that second parameter should be the size of destination buffer. As you pass strlen(fullName), there is no room for terminating \0.

    Change it to be sizeof(fullName) and your error should disappear.