]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Documentation: Fix size parameter for snprintf
authorStefan Weil <sw@weilnetz.de>
Mon, 30 Dec 2013 11:35:43 +0000 (12:35 +0100)
committerJiri Kosina <jkosina@suse.cz>
Thu, 2 Jan 2014 09:47:33 +0000 (10:47 +0100)
cppcheck reports this error:

Documentation/laptops/hpfall.c:33]: (error)
 Dangerous usage of 'devname' (strncpy doesn't always 0-terminate it)

The terminating '\0' is needed for the global char array unload_heads_path,
so never write the last array entry (which is initially '\0').

Signed-off-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Documentation/laptops/hpfall.c

index a4a8fc5d05d4e3261910b805bf668c6bfe523d15..b85dbbac049933dd9dc6f6f45568f3725246f032 100644 (file)
@@ -29,7 +29,7 @@ int set_unload_heads_path(char *device)
                return -EINVAL;
        strncpy(devname, device + 5, sizeof(devname));
 
-       snprintf(unload_heads_path, sizeof(unload_heads_path),
+       snprintf(unload_heads_path, sizeof(unload_heads_path) - 1,
                                "/sys/block/%s/device/unload_heads", devname);
        return 0;
 }