Hello. On 12/16/2013 02:30 PM, Krzysztof Opasiak wrote:
Add error handling when gadget_read_buf return NULL. If read of string fails, the string should be set as empty.
Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx> --- src/gadget.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/gadget.c b/src/gadget.c index f613c3e..5568486 100644 --- a/src/gadget.c +++ b/src/gadget.c @@ -121,11 +121,18 @@ static int gadget_read_int(char *path, char *name, char *file, int base) static void gadget_read_string(char *path, char *name, char *file, char *buf) { - char *p; + char *p = NULL; + + p = gadget_read_buf(path, name, file, buf); + //check whether read was successful + if (p != NULL) { + if (p && (p = strchr(buf, '\n')) != NULL)
You have just checked that p != NULL, why do it once again?
+ *p = '\0';
Seems over-indented. WBR, Sergei -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html