This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

I: [PATCH] asprintf error handling fix


Greetings!

Current asprintf (to be more exact, _IO_vasprintf) implementation
appears to have two defects:
- When _IO_vfprintf call fails, _IO_vasprintf returns error code without
  freeing memory allocated before (either in this function or during
  _IO_vfprintf execution).
- When either malloc or _IO_vfprintf call fails, _IO_vasprintf returns
  error code without setting result_ptr to zero.

First defect seems to have obvious fix.
You may ask why asprintf should zero result_ptr in case of error?
There are several reasons:
+ It's reasonable and expected behaviour.
+ The asprintf function is widely used by glibc itself, and almost
  everywhere it assumes result_ptr gets null value in case of error; I've tried to
  catch all such cases, but anyway better to avoid potential problems.
+ All BSD libc implementations do that, so porting asprintf based software
  from *BSD to glibc becomes a nightmare if asprintf API differs.


2001-12-05  Dmitry V. Levin <ldv@alt-linux.org>

	* libio/vasprintf.c (_IO_vasprintf): Fix error handling.
	* assert/assert-perr.c: Check asprintf return code.
	* assert/assert.c: Likewise.
	* inet/rcmd.c: Likewise.
	* locale/programs/localedef.c: Likewise.
	* posix/getopt.c: Likewise.
	* resolv/res_hconf.c: Likewise.
	* stdio-common/psignal.c: Likewise.
	* sunrpc/svc_simple.c: Likewise.
	* manual/stdio.texi: Reflect change in asprintf API.


Regards,
	Dmitry

+-------------------------------------------------------------------------+
Dmitry V. Levin     mailto://ldv@alt-linux.org
ALT Linux Team      http://www.altlinux.ru/
Fandra Project      http://www.fandra.org/
+-------------------------------------------------------------------------+
UNIX is user friendly. It's just very selective about who its friends are.

Attachment: glibc-20011205-asprintf-error_handling.patch.gz
Description: GNU Zip compressed data

Attachment: msg00021/pgp00000.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]