[parted-devel] [PATCH 4/5] ui: Add checks for prompt being NULL
Brian C. Lane
bcl at redhat.com
Wed Feb 15 19:57:10 GMT 2023
Also removes a cast from const char* to char* when passing to readline
that doesn't appear to be necessary any longer.
Added asserts to make sure prompt isn't NULL after strdup and realloc
calls.
---
parted/ui.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/parted/ui.c b/parted/ui.c
index df14e55..9e5ced2 100644
--- a/parted/ui.c
+++ b/parted/ui.c
@@ -564,8 +564,7 @@ _readline (const char* prompt, const StrList* possibilities)
wipe_line ();
#ifdef HAVE_LIBREADLINE
if (!opt_script_mode) {
- /* XXX: why isn't prompt const? */
- line = readline ((char*) prompt);
+ line = readline (prompt);
if (line)
_add_history_unique (line);
} else
@@ -781,6 +780,8 @@ realloc_and_cat (char* str, const char* append)
int length = strlen (str) + strlen (append) + 1;
char* new_str = realloc (str, length);
+ PED_ASSERT(new_str != NULL);
+
strcat (new_str, append);
return new_str;
}
@@ -789,7 +790,9 @@ static char*
_construct_prompt (const char* head, const char* def,
const StrList* possibilities)
{
+ PED_ASSERT(head != NULL);
char* prompt = strdup (head);
+ PED_ASSERT(prompt != NULL);
if (def && possibilities)
PED_ASSERT (str_list_match_any (possibilities, def));
--
2.39.1
More information about the parted-devel
mailing list