[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] ext2 bug Was Re: another getcwd fix (includes previous patch)



Alan Hourihane a wrote:
I've also attached a new getcwd.c (& unx2dos.c) fix that adds __set_errno(ENOMEM)
on out of memory conditions to ensure we return errno's correctly.

Hello, Alan !
I'm back to the MiNTLib, and I'm reviewing the pending patches.

Just a remark about __getcwd():

	if (_rootdir && drv == _rootdir) {
		if (!*path) {
			path[0] = '\\';
			path[1] = '\0';
		}
		_dos2unx(path, buf, size);
	}
	else
		/* convert DOS filename to unix */
		_dos2unx(_path, buf, size);

	free(_path);

	if (errno == ENAMETOOLONG) {
		if (buf_malloced)
			free(buf);
		return NULL;
	}

The errno handling is wrong.
1) The value of errno is relevant only when a function has failed. But you didn't check for the return value of _dos2unx() 2) The value of errno may be overwritten when functions are called, such as free(). You should check errno just after calling _dos2unx(), but only when it fails.

Then your patch will be rock-solid !

--
Vincent Rivière