From 818af4f6fa925a2affdc6d65e9d18d6922b11baf Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 23 Apr 2013 20:33:13 -0300 Subject: [PATCH] libkmod-module: Don't pass NULL pointer to memcpy When passing n=0, don't pass a NULL pointer, but instead pass anything else (like the pointer to the start of the string). --- CODING-STYLE | 9 +++++++-- libkmod/libkmod-module.c | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CODING-STYLE b/CODING-STYLE index e60df9e..865252e 100644 --- a/CODING-STYLE +++ b/CODING-STYLE @@ -15,10 +15,12 @@ them is actually an error. In certain circumstances one can ignore the 80 character per line limit. This is generally only allowed if the alternative would make the code even less readable. -Besides the kernel coding style above, kmod coding style is havily based on +Besides the kernel coding style above, kmod coding style is heavily based on oFono's and BlueZ's. Below some basic rules: -1) Wrap line at 80 char limit. There are a few exceptions: +1) Wrap line at 80 char limit. + +There are a few exceptions: - Headers may or may not wrap - If it's a string that is hitting the limit, it's preferred not to break in order to be able to grep for that string. E.g: @@ -29,6 +31,9 @@ oFono's and BlueZ's. Below some basic rules: - If there's only one argument to the function, don't put it alone in a new line. +Align the wrapped line either with tabs (BlueZ, oFono, etc) or tab + spaces +(kernel), at your discretion. Kernel's is preferred. + 2) It's better to return/exit early in a function than having a really long "if (...) { }". Example: diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 47d12ad..6b793cd 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -2100,7 +2100,7 @@ static struct kmod_module_info *kmod_module_info_new(const char *key, size_t key return NULL; info->key = (char *)info + sizeof(struct kmod_module_info) - + valuelen + 1; + + valuelen + 1; memcpy(info->key, key, keylen); info->key[keylen] = '\0'; memcpy(info->value, value, valuelen); @@ -2177,6 +2177,7 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_ if (value == NULL) { keylen = strlen(key); valuelen = 0; + value = key; } else { keylen = value - key; value++; -- 2.39.2