summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Baodong Chen2022-03-29 11:49:26 +0200
committerGravatar Nikias Bassen2022-03-29 11:49:26 +0200
commit94ed8c464dee51191f16b5758f090e920fb4d3e1 (patch)
treea3ad3ead5772e5dc0e9b650356ee9312a5064cb2
parentec932860bb6abb86e05e64935568c3678ca9b878 (diff)
downloadlibimobiledevice-94ed8c464dee51191f16b5758f090e920fb4d3e1.tar.gz
libimobiledevice-94ed8c464dee51191f16b5758f090e920fb4d3e1.tar.bz2
debugserver: Check return value of asprintf to eliminate compiler warnings
-rw-r--r--src/debugserver.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/debugserver.c b/src/debugserver.c
index b6a8b62..46686f6 100644
--- a/src/debugserver.c
+++ b/src/debugserver.c
@@ -574,14 +574,18 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_argv(debugserver
debugserver_error_t result = DEBUGSERVER_E_UNKNOWN_ERROR;
char *pkt = NULL;
- int pkt_len = 0;
+ size_t pkt_len = 0;
int i = 0;
/* calculate total length */
while (i < argc && argv && argv[i]) {
char *prefix = NULL;
- asprintf(&prefix, ",%d,%d,", (int)strlen(argv[i]) * 2, i);
- pkt_len += (int)strlen(prefix) + (int)strlen(argv[i]) * 2;
+ int ret = asprintf(&prefix, ",%zu,%d,", strlen(argv[i]) * 2, i);
+ if (ret < 0 || prefix == NULL) {
+ debug_info("asprintf failed, out of memory?");
+ return DEBUGSERVER_E_UNKNOWN_ERROR;
+ }
+ pkt_len += strlen(prefix) + strlen(argv[i]) * 2;
free(prefix);
i++;
}
@@ -598,10 +602,14 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_argv(debugserver
char *prefix = NULL;
char *m = NULL;
- int arg_len = strlen(argv[i]);
- int arg_hexlen = arg_len * 2;
+ size_t arg_len = strlen(argv[i]);
+ size_t arg_hexlen = arg_len * 2;
- asprintf(&prefix, ",%d,%d,", arg_hexlen, i);
+ int ret = asprintf(&prefix, ",%zu,%d,", arg_hexlen, i);
+ if (ret < 0 || prefix == NULL) {
+ debug_info("asprintf failed, out of memory?");
+ return DEBUGSERVER_E_UNKNOWN_ERROR;
+ }
m = (char *) malloc(arg_hexlen);
char *p = m;