Fixes (un)signed comparison warning in regex.c
The warning actually hinted at an unchecked return value.
As of this patch it is checked.
Bug: 28585892
Change-Id: Ibc09903129d3dce4d8a7b98d0313ec743fb937b5
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 @@
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 @@
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 @@
#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 @@
default:
break;
}
-
+ return;
}