Just by allocating size*2 bytes we can't be sure that new size will be enough,

so change two
	if (size not enough) {
		reallocf(size*2);
	}
into
	while (size not enough) {
		reallocf(size*2);
	}
This commit is contained in:
ache 2005-09-18 17:50:58 +00:00
parent 64eedb0310
commit 470e1e4236

View File

@ -157,7 +157,7 @@ getcwd(pt, size)
* as necessary. Max length is 3 for "../", the largest
* possible component name, plus a trailing NUL.
*/
if (bup + 3 + MAXNAMLEN + 1 >= eup) {
while (bup + 3 + MAXNAMLEN + 1 >= eup) {
if ((up = reallocf(up, upsize *= 2)) == NULL)
goto err;
bup = up;
@ -211,7 +211,7 @@ getcwd(pt, size)
* Check for length of the current name, preceding slash,
* leading slash.
*/
if (bpt - pt < dp->d_namlen + (first ? 1 : 2)) {
while (bpt - pt < dp->d_namlen + (first ? 1 : 2)) {
size_t len, off;
if (!ptsize) {