Correct usage of g_read_data() API

From: Maxim Sobolev (sobomax_at_portaone.com)
Date: 11/29/05

  • Next message: Maxim Sobolev: "Re: New libc malloc patch"
    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"


  • Next message: Maxim Sobolev: "Re: New libc malloc patch"

    Relevant Pages

    • [ANNOUNCE] GIT 1.5.0-rc3
      ... This contains the "git user's manual" by J. Bruce Fields. ... Fix git-update-index to work with relative pathnames. ... Documentation: add git user's manual ... reflog gc: a tag that does not point at a commit is not a crime. ...
      (Linux-Kernel)
    • Whats in git.git (stable)
      ... Updates to gitk from Paul Mackerras to fix longstanding menu ... Eric also has quite a few fixes to git-svn. ... documentation for 'git commit' to make it easier to teach new ... Hide plumbing/transport commands from bash completion. ...
      (Linux-Kernel)
    • 2.6.9-rc2-mm2
      ... It has a number of tunables and lots of documentation - see the changelog ... This is the code which uses kexec ... Fix fsync() with ext3's data=journal mode ... Hack around ia64 non-compile problem. ...
      (Linux-Kernel)
    • [ANNOUNCE] GIT 1.4.0
      ... You can "alias" git commands with leading arguments in your ... Documentation set, especially the tutorial, has been reworked. ... Builtin git-rev-parse. ... Fix git-pack-objects for 64-bit platforms ...
      (Linux-Kernel)
    • [ANNOUNCE] Cogito-0.17.1
      ... line of the Cogito user-friendly Git user interface. ... Random documentation updates ... Clean up after failed "git merge" in the tutorial script ... Fix some relpath-related cg-add and cg-status bugs ...
      (Linux-Kernel)