summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanis Danisevskis <jdanis@google.com>2016-05-05 13:08:17 +0100
committerJanis Danisevskis <jdanis@google.com>2016-05-05 18:43:13 +0100
commita9677b666c6ae598291f8b7757bef967b6338335 (patch)
tree8710c7f0ddde5589d974adaf8a0fed4e7fa20ac6
parent31f5cd6e3ea8ed34a35bf43bf135565301ad7062 (diff)
downloadlibselinux-a9677b666c6ae598291f8b7757bef967b6338335.tar.gz
The warning actually hinted at an unchecked return value. As of this patch it is checked. Bug: 28585892 Change-Id: Ibc09903129d3dce4d8a7b98d0313ec743fb937b5
-rw-r--r--src/regex.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/regex.c b/src/regex.c
index 7a0d7e9..4223b02 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -327,10 +327,12 @@ void regex_format_error(struct regex_error_data const * error_data,
if (!buffer || !buf_size)
return;
rc = snprintf(buffer, buf_size, "REGEX back-end error: ");
- if (rc < 0) {
- buffer[0] = '\0';
- return;
- }
+ if (rc < 0)
+ /* If snprintf fails it constitutes a logical error that needs
+ * fixing.
+ */
+ abort();
+
pos += rc;
if (pos >= buf_size)
goto truncated;
@@ -343,10 +345,9 @@ void regex_format_error(struct regex_error_data const * error_data,
rc = snprintf(buffer + pos, buf_size - pos, "At offset %d: ",
error_data->error_offset);
#endif
- if (rc < 0) {
- buffer[0] = '\0';
- return;
- }
+ if (rc < 0)
+ abort();
+
}
pos += rc;
if (pos >= buf_size)
@@ -361,13 +362,16 @@ void regex_format_error(struct regex_error_data const * error_data,
#else
rc = snprintf(buffer + pos, buf_size - pos, "%s",
error_data->error_buffer);
- if (rc < strlen(error_data->error_buffer))
+ if (rc < 0)
+ abort();
+
+ if ((size_t)rc < strlen(error_data->error_buffer))
goto truncated;
#endif
return;
- truncated:
+truncated:
/* replace end of string with "..." to indicate that it was truncated */
switch (the_end_length) {
/* no break statements, fall-through is intended */
@@ -382,5 +386,5 @@ void regex_format_error(struct regex_error_data const * error_data,
default:
break;
}
-
+ return;
}