Correct usage of g_read_data() API
From: Maxim Sobolev (sobomax_at_portaone.com)
Date: 11/29/05
- Previous message: Hiten Pandya: "Re: New libc malloc patch"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Nov 2005 03:07:30 -0800 To: phk@freebsd.org
Hi Poul,
After making a fix for geom_label (rev.1.4 of g_label_ntfs.c) I have
decided to check if there are any other places which don't check return
values of g_read_data(9).
What I found however is that there are several different usage patterns,
some of which rely on undocumented internal properties of the said API,
particularly:
--- 1 ---
error = random();
data = g_read_data(..., &error);
if (error != 0)
handle_error(error);
---------
--- 2 ---
error = random();
data = g_read_data(..., &error);
if (buf == NULL || error != 0)
handle_error(error);
---------
--- 3 ---
error = random();
data = g_read_data(..., &error);
if (buf == NULL)
handle_error(error);
---------
According to my reading of g_read_data(9) only (3) is valid, since both
(1) and (2) assume that error will always be cleared on successful
completion, while (1) also assumes that error will be set to non-zero
value in all cases when error happens and (2) assumes that non-NULL
value can be returned even on error.
Therefore, either documentation should be extended to match
implementation or usage of g_read_data() fixed in all places where it is
incorrect.
Please advise.
-Maxim
P.S. I can do the actual changes by myself, both to documentation and/or
to code.
_______________________________________________
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"
- Previous message: Hiten Pandya: "Re: New libc malloc patch"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|