diff --git a/include/ss/common.hpp b/include/ss/common.hpp index 305503c..c9185f8 100644 --- a/include/ss/common.hpp +++ b/include/ss/common.hpp @@ -62,10 +62,10 @@ ssize_t get_line(char** lineptr, size_t* n, FILE* fp) { size_t line_used = strlen(*lineptr); size_t buff_used = strlen(buff); - if (*n < buff_used + line_used) { + if (*n <= buff_used + line_used) { size_t new_n = *n * 2; - auto new_lineptr = static_cast(realloc(*lineptr, *n)); + auto new_lineptr = static_cast(realloc(*lineptr, new_n)); if (new_lineptr == nullptr) { errno = ENOMEM; return -1; diff --git a/ssp.hpp b/ssp.hpp index 9bc953b..71d05cf 100644 --- a/ssp.hpp +++ b/ssp.hpp @@ -674,10 +674,10 @@ ssize_t get_line(char** lineptr, size_t* n, FILE* fp) { size_t line_used = strlen(*lineptr); size_t buff_used = strlen(buff); - if (*n < buff_used + line_used) { + if (*n <= buff_used + line_used) { size_t new_n = *n * 2; - auto new_lineptr = static_cast(realloc(*lineptr, *n)); + auto new_lineptr = static_cast(realloc(*lineptr, new_n)); if (new_lineptr == nullptr) { errno = ENOMEM; return -1;