diff --git a/src/bin/mimeset.cpp b/src/bin/mimeset.cpp index b83b4a96f9..263bdefe32 100644 --- a/src/bin/mimeset.cpp +++ b/src/bin/mimeset.cpp @@ -238,8 +238,10 @@ main(int argc, const char** argv) // read file names from stdin char name[B_PATH_NAME_LENGTH]; while (fgets(name, sizeof(name), stdin) != NULL) { - name[strlen(name) - 1] = '\0'; - // remove trailing '\n' + if (name[0] != '\0') { + name[strlen(name) - 1] = '\0'; + // remove trailing '\n' + } if (process_file(name) != B_OK) exit(1); } diff --git a/src/bin/pc/pc.c b/src/bin/pc/pc.c index 05fb9123f1..92d6e8161f 100644 --- a/src/bin/pc/pc.c +++ b/src/bin/pc/pc.c @@ -284,7 +284,7 @@ do_input(void) while(fgets(buff, 256, stdin) != NULL) { - if (buff[strlen(buff)-1] == '\n') + if (buff[0] != '\0' && buff[strlen(buff)-1] == '\n') buff[strlen(buff)-1] = '\0'; /* kill the newline character */ for(ptr=buff; isspace(*ptr) && *ptr; ptr++) diff --git a/src/libs/bsd/getpass.c b/src/libs/bsd/getpass.c index 45676c0b3e..65485ceadb 100644 --- a/src/libs/bsd/getpass.c +++ b/src/libs/bsd/getpass.c @@ -38,7 +38,7 @@ getpass(const char *prompt) if (fgets(password, sizeof(password), stdin) != NULL) { size_t length = strlen(password); - if (password[length - 1] == '\n') + if (length > 0 && (password[length - 1] == '\n')) password[length - 1] = '\0'; if (changed) {