[patch 3/5] Driver core: Documentation: use snprintf and strnlen

domen_at_coderock.org
Date: 07/31/05

  • Next message: domen_at_coderock.org: "[patch 1/5] drivers/char/lp.c : Use of the time_after() macro"
    Date:	Sun, 31 Jul 2005 13:12:08 +0200
    To: akpm@osdl.org
    
    

    From: Jan Veldeman <jan@mind.be>

    Documentation should give the good example of using snprintf and
    strnlen in stead of sprintf and strlen.

    PAGE_SIZE is used as the maximal length to reflect the behaviour of
    show/store.

    Signed-off-by: Jan Veldeman <Jan.Veldeman@advalvas.be>
    Signed-off-by: Domen Puncer <domen@coderock.org>

    ---
     sysfs.txt |    4 ++--
     1 files changed, 2 insertions(+), 2 deletions(-)
    Index: quilt/Documentation/filesystems/sysfs.txt
    ===================================================================
    --- quilt.orig/Documentation/filesystems/sysfs.txt
    +++ quilt/Documentation/filesystems/sysfs.txt
    @@ -216,13 +216,13 @@ A very simple (and naive) implementation
     
     static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
     {
    -        return sprintf(buf,"%s\n",dev->name);
    +        return snprintf(buf,PAGE_SIZE,"%s\n",dev->name);
     }
     
     static ssize_t store_name(struct device * dev, const char * buf)
     {
     	sscanf(buf,"%20s",dev->name);
    -	return strlen(buf);
    +	return strnlen(buf,PAGE_SIZE);
     }
     
     static DEVICE_ATTR(name,S_IRUGO,show_name,store_name);
    --
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: domen_at_coderock.org: "[patch 1/5] drivers/char/lp.c : Use of the time_after() macro"

    Relevant Pages

    • Re: memory allocation error messages in system log
      ... there are a lot of sprintf() in gdth_get_info. ... There are a few overflow ... > exact same bug (memory allocation failure while reading ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • include/linux/nfs/nfsfh.h declares a symbol
      ... Neil, the function SVCFH_fmt uses a static variable to sprintf into. ... to thine own self be true. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [PATCH] vsprintf.c cleanups
      ... On Fri, 25 Feb 2005, Horst von Brand wrote: ... >> Sprintf has no limit, which is why it's generally bad to use it. ... snprintf() is in the sprintfwrapper that calls snprintf. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [PATCH] vsprintf.c cleanups
      ... Horst von Brand wrote: ... Sprintf has no limit, which is why it's generally bad to use it. ... send the line "unsubscribe linux-kernel" in ... Please read the FAQ at http://www.tux.org/lkml/ ...
      (Linux-Kernel)