summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanis Danisevskis <jdanis@google.com>2016-05-06 16:41:51 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-05-06 16:41:51 +0000
commit4740379d9ee2b56cb565437c43e374c07ff36dc9 (patch)
tree7e60446f938e62e97309a2da72a36f2b6bea9e0a
parentd2ebe5cfa7b39242bb7c2fb44feecedeef2aa370 (diff)
parent9ba0af9eaef8742b5fec684d4faa7c398b100485 (diff)
downloadlibselinux-4740379d9ee2b56cb565437c43e374c07ff36dc9.tar.gz
Fixes (un)signed comparison warning in regex.c am: a9677b666c
am: 9ba0af9eae * commit '9ba0af9eaef8742b5fec684d4faa7c398b100485': Fixes (un)signed comparison warning in regex.c Change-Id: I8204ae2a9086f74865d22dc1c7c482e13f492eaa
-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;
}