fix off-by-one error

This commit is contained in:
Enno Rehling 2016-02-20 22:23:19 +01:00
parent ca6bc638ed
commit 1682b3d583
2 changed files with 5 additions and 2 deletions

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 3 #define VERSION_MAJOR 3
#define VERSION_MINOR 7 #define VERSION_MINOR 7
#define VERSION_BUILD 13 #define VERSION_BUILD 14

View File

@ -1156,7 +1156,7 @@ void write_spellbook(const struct spellbook *book, struct storage *store)
WRITE_TOK(store, "end"); WRITE_TOK(store, "end");
} }
char * getpasswd(int fno) { static char * getpasswd(int fno) {
const char *prefix = itoa36(fno); const char *prefix = itoa36(fno);
size_t len = strlen(prefix); size_t len = strlen(prefix);
FILE * F = fopen("passwords.txt", "r"); FILE * F = fopen("passwords.txt", "r");
@ -1165,6 +1165,9 @@ char * getpasswd(int fno) {
while (!feof(F)) { while (!feof(F)) {
fgets(line, sizeof(line), F); fgets(line, sizeof(line), F);
if (line[len]==':' && strncmp(prefix, line, len)==0) { if (line[len]==':' && strncmp(prefix, line, len)==0) {
size_t slen = strlen(line)-1;
assert(line[slen]=='\n');
line[slen] = 0;
fclose(F); fclose(F);
return _strdup(line+len+1); return _strdup(line+len+1);
} }