Skip to content
This repository has been archived by the owner on Jun 5, 2018. It is now read-only.

Commit

Permalink
Extend the "don't overwrite fields if only carriage return is entered…
Browse files Browse the repository at this point in the history
…" to password field

And also use malloc. What I'd done before wasn't doing what I thought. C
newbie and all that. It must have picked up whatever `input` was
initialised at, which must be one of STRING_SHORT, STRING_MEDIUM, etc.
So it was just by luck it was working. It could have ended up truncating
strings I guess?

I'm in two minds about the benefit of dynamic allocation though. Since
this is hardly a big memory hungry application I could probably just
set `oldinput` to the largest possible string length and it'd be fine.
  • Loading branch information
atomicules committed Mar 23, 2013
1 parent bbe299d commit 98593a8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,10 @@ ui_statusline_ask_str(char *msg, char *input, int len)
char *tmp;
char *tmp2;
char *tmp3;
char oldinput[strlen(input)];
char *oldinput;
int x = strlen(msg) + 5;

oldinput = malloc(strlen(input)+1);
//Back-up the old value
strcpy(oldinput, input);

Expand Down Expand Up @@ -525,6 +526,7 @@ ui_statusline_ask_str(char *msg, char *input, int len)
}

// All done
free(oldinput);
return input;
}

Expand All @@ -534,8 +536,13 @@ ui_statusline_ask_str_with_autogen(char *msg, char *input, int len, char *(*auto
int i = 0;
int c;
char *text[2], *s;
char *oldinput;
int x;

oldinput = malloc(strlen(input)+1);
//Back-up the old value
strcpy(oldinput, input);

if(input == NULL){
input = malloc(len);
}
Expand Down Expand Up @@ -582,8 +589,14 @@ ui_statusline_ask_str_with_autogen(char *msg, char *input, int len, char *(*auto

ui_statusline_clear();

//If just return entered, don't overwrite old value
if(strlen(input) == 0){
strcpy(input, oldinput);
}

free(text[0]);
free(text[1]);
free(oldinput);

return input;
}
Expand Down

0 comments on commit 98593a8

Please sign in to comment.