Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Nov 2005 03:07:30 -0800
From:      Maxim Sobolev <sobomax@portaone.com>
To:        phk@freebsd.org
Cc:        "current@freebsd.org" <current@freebsd.org>
Subject:   Correct usage of g_read_data() API
Message-ID:  <438C3672.1010700@portaone.com>

next in thread | raw e-mail | index | archive | help
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?438C3672.1010700>