Skip to content
Snippets Groups Projects
Commit 8cb73d2c authored by Andreas Gattringer's avatar Andreas Gattringer Committed by Andreas Gattringer
Browse files

cats_strings: new helper function for safely accessing the nth string

parent 285d07ea
No related branches found
No related tags found
No related merge requests found
...@@ -136,6 +136,17 @@ struct string_array *new_string_array() ...@@ -136,6 +136,17 @@ struct string_array *new_string_array()
return result; return result;
} }
const char *get_nth_string_from_array(const struct string_array *array, int n)
{
assert(array != NULL);
if (n < 0 && n >= array->count) {
log_message(LOG_ERROR, "%s: requested string index %d out of range [0, %d]", __func__ , n, array->count);
exit(EXIT_FAILURE);
}
return array->string[n];
}
struct string_array *new_string_array_init(const char *entry) struct string_array *new_string_array_init(const char *entry)
{ {
......
...@@ -88,7 +88,7 @@ void string_array_add_double(struct string_array *array, double number, const ch ...@@ -88,7 +88,7 @@ void string_array_add_double(struct string_array *array, double number, const ch
void void
string_array_add_int_conditional(struct string_array *array, int32_t number, const char *format_string, bool condition); string_array_add_int_conditional(struct string_array *array, int32_t number, const char *format_string, bool condition);
const char *get_nth_string_from_array(const struct string_array *array, int n);
void print_string_array(const struct string_array *array); void print_string_array(const struct string_array *array);
char *remove_0th_token(char *line, const char *sep); char *remove_0th_token(char *line, const char *sep);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment