Correct usage of g_read_data() API
Maxim Sobolev
sobomax at portaone.com
Tue Nov 29 11:07:38 GMT 2005
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.
More information about the freebsd-current
mailing list