Subject: Implementation of asprintf()/vasprintf()
To: None <tech-userlevel@netbsd.org>
From: Matthias Scheler <tron@zhadum.de>
List: tech-userlevel
Date: 09/30/2001 07:07:57
	Hello,

after calling vfprintf() our implementations of asprintf() and vasprintf()
both do this:

	_base = realloc(f._bf._base, (size_t)(ret + 1));
	if (_base == NULL)
		goto err;
	*str = (char *)_base;
	return (ret);

It appears to me that this code is supposed to avoid wasting memory if
the buffer is bigger than the result string. I only wonder if the
error handling should look like this:

	_base = realloc(f._bf._base, (size_t)(ret + 1));
	*str = (_base == NULL) ? f._bf._base : _base;
	return (ret);

This would avoid an unnecessary failure if the realloc() call fails.

	Kind regards

-- 
Matthias Scheler                                  http://scheler.de/~matthias/