summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--functions.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/functions.c b/functions.c
index ffd94f1..bc4680d 100644
--- a/functions.c
+++ b/functions.c
@@ -78,8 +78,11 @@ int getstdin(char *prompt, char *buff, size_t sz) {
// Append CR-LF to the end of a string (after cleaning up any existing trailing CR or LF)
void appendcrlf(char *string) {
// Make sure it doesn't already end with CR or LF
- while (string[strlen(string) - 1] == '\r' || string[strlen(string) - 1] == '\n') {
- string[strlen(string) - 1] = '\0';
+ // (But only if string is at least two characters long already)
+ if (strlen(string) >= 2) {
+ while (string[strlen(string) - 1] == '\r' || string[strlen(string) - 1] == '\n') {
+ string[strlen(string) - 1] = '\0';
+ }
}
int startlen = strlen(string);