[Asterisk-code-review] geolocation & test: Fix issues exposed by compiling with -O2 (asterisk[19.7])

George Joseph asteriskteam at digium.com
Fri Sep 16 08:49:58 CDT 2022


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19283 )


Change subject: geolocation & test: Fix issues exposed by compiling with -O2
......................................................................

geolocation & test: Fix issues exposed by compiling with -O2

Fixed "may be used uninitialized" errors in geoloc_config.c,
test.c and test_crypto.c.  Also changed a few direct calls to
alloca and free to use the ast_ variants.

ASTERISK-30234

Change-Id: I1ea336bf7abbc16fa59b75720f0db8f1d960b3d4
---
M main/test.c
M res/res_geolocation/geoloc_config.c
M tests/test_crypto.c
3 files changed, 22 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/83/19283/1

diff --git a/main/test.c b/main/test.c
index 747262c..d01392e 100644
--- a/main/test.c
+++ b/main/test.c
@@ -316,9 +316,9 @@
 void ast_test_capture_free(struct ast_test_capture *capture)
 {
 	if (capture) {
-		free(capture->outbuf);
+		ast_free(capture->outbuf);
 		capture->outbuf = NULL;
-		free(capture->errbuf);
+		ast_free(capture->errbuf);
 		capture->errbuf = NULL;
 	}
 	capture->pid = -1;
@@ -330,6 +330,7 @@
 	int fd0[2] = { -1, -1 }, fd1[2] = { -1, -1 }, fd2[2] = { -1, -1 };
 	pid_t pid = -1;
 	int status = 0;
+	FILE *cmd = NULL, *out = NULL, *err = NULL;
 
 	memset(capture, 0, sizeof(*capture));
 	capture->pid = capture->exitcode = -1;
@@ -379,8 +380,6 @@
 		exit(1);
 
 	} else {
-		FILE *cmd = NULL, *out = NULL, *err = NULL;
-
 		char buf[BUFSIZ];
 		int wstatus, n, nfds;
 		fd_set readfds, writefds;
diff --git a/res/res_geolocation/geoloc_config.c b/res/res_geolocation/geoloc_config.c
index dea7a22..26dd2d9 100644
--- a/res/res_geolocation/geoloc_config.c
+++ b/res/res_geolocation/geoloc_config.c
@@ -187,7 +187,7 @@
 	struct ast_geoloc_location *location;
 	const char *id = ast_sorcery_object_get_id(profile);
 	enum ast_geoloc_validate_result result;
-	enum ast_geoloc_format format;
+	enum ast_geoloc_format format = AST_GEOLOC_FORMAT_NONE;
 	int rc = 0;
 
 	if (!ast_strlen_zero(profile->location_reference)) {
diff --git a/tests/test_crypto.c b/tests/test_crypto.c
index 141781b..a3a0004 100644
--- a/tests/test_crypto.c
+++ b/tests/test_crypto.c
@@ -49,7 +49,7 @@
 
 static char *hexstring(const unsigned char *data, unsigned datalen)
 {
-	char *buf = alloca(datalen * 2 + 1);
+	char *buf = ast_malloc(datalen * 2 + 1);
 	unsigned n;
 
 	for (n = 0; n < datalen; ++n) {
@@ -532,6 +532,7 @@
 	res = AST_TEST_PASS;
 
 cleanup:
+	ast_free(args[KEY]);
 	ast_test_capture_free(&cap);
 	return res;
 }
@@ -610,6 +611,7 @@
 	res = AST_TEST_PASS;
 
 cleanup:
+	ast_free(args[KEY]);
 	ast_test_capture_free(&cap);
 	return res;
 }

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19283
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 19.7
Gerrit-Change-Id: I1ea336bf7abbc16fa59b75720f0db8f1d960b3d4
Gerrit-Change-Number: 19283
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220916/13c7c02f/attachment-0001.html>


More information about the asterisk-code-review mailing list