diff options
author | taeyoung <ty317.kim@samsung.com> | 2016-09-23 16:35:45 +0900 |
---|---|---|
committer | taeyoung <ty317.kim@samsung.com> | 2016-09-23 17:10:58 +0900 |
commit | d25dbaed77aeb19345d57af73f64989a1d5e6265 (patch) | |
tree | ae942af9a18b406470a7a56c8e4f1c6052cc0181 | |
parent | e45f1517b996d57654d5edf918981fe2d64a575f (diff) | |
download | libusbg-d25dbaed77aeb19345d57af73f64989a1d5e6265.tar.gz libusbg-d25dbaed77aeb19345d57af73f64989a1d5e6265.tar.bz2 libusbg-d25dbaed77aeb19345d57af73f64989a1d5e6265.zip |
common: fix minor issues.submit/tizen/20160923.084807
- thread unsafe functions are removed.
- sprintf is changed to snprintf
Change-Id: I129984005ae538496a1135cbc8a191f588a432ff
Signed-off-by: taeyoung <ty317.kim@samsung.com>
-rw-r--r-- | examples/gadget-export.c | 2 | ||||
-rw-r--r-- | examples/gadget-import.c | 2 | ||||
-rw-r--r-- | include/usbg/usbg_internal.h | 6 | ||||
-rw-r--r-- | src/usbg.c | 12 | ||||
-rw-r--r-- | src/usbg_schemes_libconfig.c | 9 | ||||
-rw-r--r-- | tests/usbg-test.c | 11 |
6 files changed, 24 insertions, 18 deletions
diff --git a/examples/gadget-export.c b/examples/gadget-export.c index 9d51e9e..15059fa 100644 --- a/examples/gadget-export.c +++ b/examples/gadget-export.c @@ -43,7 +43,7 @@ int main(int argc, char **argv) /* Prepare output file */ output = fopen(argv[2], "w"); if (!output) { - fprintf(stderr, "Error on fopen. Error: %s\n", strerror(errno)); + fprintf(stderr, "Error on fopen. Error: %d\n", errno); goto out1; } diff --git a/examples/gadget-import.c b/examples/gadget-import.c index e684fdb..a57e5da 100644 --- a/examples/gadget-import.c +++ b/examples/gadget-import.c @@ -42,7 +42,7 @@ int main(int argc, char **argv) /* Prepare input file */ input = fopen(argv[2], "r"); if (!input) { - fprintf(stderr, "Error on fopen. Error: %s\n", strerror(errno)); + fprintf(stderr, "Error on fopen. Error: %d\n", errno); goto out1; } diff --git a/include/usbg/usbg_internal.h b/include/usbg/usbg_internal.h index 30d3fcf..9331e46 100644 --- a/include/usbg/usbg_internal.h +++ b/include/usbg/usbg_internal.h @@ -130,8 +130,8 @@ struct usbg_udc } while (0) #define ERRORNO(msg, ...) do {\ - fprintf(stderr, "%s() %s: "msg" \n", \ - __func__, strerror(errno), ##__VA_ARGS__);\ + fprintf(stderr, "%s() errno:%d: "msg" \n", \ + __func__, errno, ##__VA_ARGS__);\ fflush(stderr);\ } while (0) @@ -168,7 +168,7 @@ static inline int file_select(const struct dirent *dent) int usbg_translate_error(int error); -char *usbg_ether_ntoa_r(const struct ether_addr *addr, char *buf); +char *usbg_ether_ntoa_r(const struct ether_addr *addr, char *buf, size_t len); #endif /* USBG_INTERNAL_H */ @@ -901,9 +901,9 @@ static int usbg_rm_all_dirs(const char *path) return ret; } -char *usbg_ether_ntoa_r(const struct ether_addr *addr, char *buf) +char *usbg_ether_ntoa_r(const struct ether_addr *addr, char *buf, size_t len) { - sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", + snprintf(buf, len, "%02x:%02x:%02x:%02x:%02x:%02x", addr->ether_addr_octet[0], addr->ether_addr_octet[1], addr->ether_addr_octet[2], addr->ether_addr_octet[3], addr->ether_addr_octet[4], addr->ether_addr_octet[5]); @@ -3090,12 +3090,12 @@ int usbg_set_function_net_attrs(usbg_function *f, const usbg_f_net_attrs *attrs) goto out; } - addr = usbg_ether_ntoa_r(&attrs->dev_addr, addr_buf); + addr = usbg_ether_ntoa_r(&attrs->dev_addr, addr_buf, sizeof(addr_buf)); ret = usbg_write_string(f->path, f->name, "dev_addr", addr); if (ret != USBG_SUCCESS) goto out; - addr = usbg_ether_ntoa_r(&attrs->host_addr, addr_buf); + addr = usbg_ether_ntoa_r(&attrs->host_addr, addr_buf, sizeof(addr_buf)); ret = usbg_write_string(f->path, f->name, "host_addr", addr); if (ret != USBG_SUCCESS) goto out; @@ -3390,7 +3390,7 @@ int usbg_set_net_dev_addr(usbg_function *f, struct ether_addr *dev_addr) if (f && dev_addr) { char str_buf[USBG_MAX_STR_LENGTH]; - char *str_addr = usbg_ether_ntoa_r(dev_addr, str_buf); + char *str_addr = usbg_ether_ntoa_r(dev_addr, str_buf, sizeof(str_buf)); ret = usbg_write_string(f->path, f->name, "dev_addr", str_addr); } else { ret = USBG_ERROR_INVALID_PARAM; @@ -3405,7 +3405,7 @@ int usbg_set_net_host_addr(usbg_function *f, struct ether_addr *host_addr) if (f && host_addr) { char str_buf[USBG_MAX_STR_LENGTH]; - char *str_addr = usbg_ether_ntoa_r(host_addr, str_buf); + char *str_addr = usbg_ether_ntoa_r(host_addr, str_buf, sizeof(str_buf)); ret = usbg_write_string(f->path, f->name, "host_addr", str_addr); } else { ret = USBG_ERROR_INVALID_PARAM; diff --git a/src/usbg_schemes_libconfig.c b/src/usbg_schemes_libconfig.c index c8944ed..77638ce 100644 --- a/src/usbg_schemes_libconfig.c +++ b/src/usbg_schemes_libconfig.c @@ -326,7 +326,7 @@ static int usbg_export_f_net_attrs(usbg_f_net_attrs *attrs, if (!node) goto out; - addr = usbg_ether_ntoa_r(&attrs->dev_addr, addr_buf); + addr = usbg_ether_ntoa_r(&attrs->dev_addr, addr_buf, sizeof(addr_buf)); cfg_ret = config_setting_set_string(node, addr); if (cfg_ret != CONFIG_TRUE) { ret = USBG_ERROR_OTHER_ERROR; @@ -337,7 +337,7 @@ static int usbg_export_f_net_attrs(usbg_f_net_attrs *attrs, if (!node) goto out; - addr = usbg_ether_ntoa_r(&attrs->host_addr, addr_buf); + addr = usbg_ether_ntoa_r(&attrs->host_addr, addr_buf, sizeof(addr_buf)); cfg_ret = config_setting_set_string(node, addr); if (cfg_ret != CONFIG_TRUE) { ret = USBG_ERROR_OTHER_ERROR; @@ -1120,7 +1120,7 @@ static int usbg_import_f_ms_attrs(config_setting_t *root, usbg_function *f) } luns_node = config_setting_get_member(root, "luns"); - if (!node) { + if (!luns_node) { ret = USBG_ERROR_INVALID_PARAM; goto out; } @@ -1861,6 +1861,9 @@ static int usbg_import_gadget_strings(config_setting_t *root, usbg_gadget *g) for (i = 0; i < count; ++i) { node = config_setting_get_elem(root, i); + if (!node) + continue; + if (!config_setting_is_group(node)) { ret = USBG_ERROR_INVALID_TYPE; break; diff --git a/tests/usbg-test.c b/tests/usbg-test.c index c332795..e480ca9 100644 --- a/tests/usbg-test.c +++ b/tests/usbg-test.c @@ -1089,18 +1089,21 @@ static void pull_function_net_attrs(struct test_function *func, usbg_f_net_attrs { char *path; char *content; + size_t len; safe_asprintf(&path, "%s/%s/dev_addr", func->path, func->name); - content = safe_malloc(ETHER_ADDR_STR_LEN * sizeof(char)); - usbg_ether_ntoa_r(&attrs->dev_addr, content); + len = ETHER_ADDR_STR_LEN * sizeof(char); + + content = safe_malloc(len); + usbg_ether_ntoa_r(&attrs->dev_addr, content, len); EXPECT_WRITE(path, content); safe_asprintf(&path, "%s/%s/host_addr", func->path, func->name); - content = safe_malloc(ETHER_ADDR_STR_LEN * sizeof(char)); - usbg_ether_ntoa_r(&attrs->host_addr, content); + content = safe_malloc(len); + usbg_ether_ntoa_r(&attrs->host_addr, content, len); EXPECT_WRITE(path, content); |