Correct usage of g_read_data() API

From: Maxim Sobolev <sobomax_at_portaone.com>
Date: Tue, 29 Nov 2005 03:07:30 -0800
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.
Received on Tue Nov 29 2005 - 10:07:38 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:48 UTC