[Asterisk-code-review] test crypto.c: Fix getcwd(…) build error. (asterisk[20])

Friendly Automation asteriskteam at digium.com
Tue Feb 28 07:41:56 CST 2023


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/19941 )

Change subject: test_crypto.c: Fix getcwd(…) build error.
......................................................................

test_crypto.c: Fix getcwd(…) build error.

`getcwd(…)` is decorated with the `warn_unused_result` attribute and
therefore needs its return value checked.

Change-Id: Idcccb20a0abf293202c28633d0e9ee0f6a9dbe93
---
M tests/test_crypto.c
1 file changed, 40 insertions(+), 4 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit




diff --git a/tests/test_crypto.c b/tests/test_crypto.c
index 848a562..8b52c9d 100644
--- a/tests/test_crypto.c
+++ b/tests/test_crypto.c
@@ -110,10 +110,16 @@
 
 	if (!ast_check_command_in_path(command)) {
 		ast_test_status_update(test, "couldn't find %s\n", command);
+		ast_test_capture_free(&cap);
 		return res;
 	}
 
-	getcwd(wd, sizeof(wd));
+	if (getcwd(wd, sizeof(wd)) == NULL) {
+		ast_test_status_update(test, "Could not determine current working directory\n");
+		ast_test_capture_free(&cap);
+		return res;
+	}
+
 	snprintf(key_dir, sizeof(key_dir), "%s/%s", wd, "tests/keys");
 	push_key_dir((const char *)key_dir);
 	snprintf(priv, sizeof(priv), "%s/%s.key", key_dir, keypair1);
@@ -200,10 +206,16 @@
 
 	if (!ast_check_command_in_path(command)) {
 		ast_test_status_update(test, "couldn't find %s\n", command);
+		ast_test_capture_free(&cap);
 		return res;
 	}
 
-	getcwd(wd, sizeof(wd));
+	if (getcwd(wd, sizeof(wd)) == NULL) {
+		ast_test_status_update(test, "Could not determine current working directory\n");
+		ast_test_capture_free(&cap);
+		return res;
+	}
+
 	snprintf(key_dir, sizeof(key_dir), "%s/%s", wd, "tests/keys");
 	push_key_dir((const char *)key_dir);
 	snprintf(pub, sizeof(pub), "%s/%s.pub", key_dir, keypair1);
@@ -297,10 +309,16 @@
 
 	if (!ast_check_command_in_path(command)) {
 		ast_test_status_update(test, "couldn't find %s\n", command);
+		ast_test_capture_free(&cap);
 		return res;
 	}
 
-	getcwd(wd, sizeof(wd));
+	if (getcwd(wd, sizeof(wd)) == NULL) {
+		ast_test_status_update(test, "Could not determine current working directory\n");
+		ast_test_capture_free(&cap);
+		return res;
+	}
+
 	snprintf(key_dir, sizeof(key_dir), "%s/%s", wd, "tests/keys");
 	push_key_dir((const char *)key_dir);
 	snprintf(pub, sizeof(pub), "%s/%s.pub", key_dir, keypair1);
@@ -410,10 +428,16 @@
 
 	if (!ast_check_command_in_path(command)) {
 		ast_test_status_update(test, "couldn't find %s\n", command);
+		ast_test_capture_free(&cap);
 		return res;
 	}
 
-	getcwd(wd, sizeof(wd));
+	if (getcwd(wd, sizeof(wd)) == NULL) {
+		ast_test_status_update(test, "Could not determine current working directory\n");
+		ast_test_capture_free(&cap);
+		return res;
+	}
+
 	snprintf(key_dir, sizeof(key_dir), "%s/%s", wd, "tests/keys");
 	push_key_dir((const char *)key_dir);
 	snprintf(priv, sizeof(priv), "%s/%s.key", key_dir, keypair1);

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

Gerrit-Project: asterisk
Gerrit-Branch: 20
Gerrit-Change-Id: Idcccb20a0abf293202c28633d0e9ee0f6a9dbe93
Gerrit-Change-Number: 19941
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230228/666d60d6/attachment.html>


More information about the asterisk-code-review mailing list