forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch upb to fix build error with gcc 10 (third_party)
Closes bazelbuild#12088
- Loading branch information
1 parent
796d0ee
commit 4ebea2c
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
commit 9bd23dab4240b015321a53c45b3c9e4847fbf020 | ||
Author: Joshua Haberman <[email protected]> | ||
Date: Tue Apr 7 15:22:11 2020 -0700 | ||
|
||
Changed upb status to suit GCC10's warning about strncpy(). (#268) | ||
|
||
Added tests for all cases. Also removed ellipses from truncated | ||
messages, they were more trouble than they are worth. | ||
|
||
diff --git a/upb/upb.c b/upb/upb.c | ||
index cb2cdfd..258192d 100644 | ||
--- a/upb/upb.c | ||
+++ b/upb/upb.c | ||
@@ -11,17 +11,6 @@ | ||
|
||
#include "upb/port_def.inc" | ||
|
||
-/* Guarantee null-termination and provide ellipsis truncation. | ||
- * It may be tempting to "optimize" this by initializing these final | ||
- * four bytes up-front and then being careful never to overwrite them, | ||
- * this is safer and simpler. */ | ||
-static void nullz(upb_status *status) { | ||
- const char *ellipsis = "..."; | ||
- size_t len = strlen(ellipsis); | ||
- UPB_ASSERT(sizeof(status->msg) > len); | ||
- memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len); | ||
-} | ||
- | ||
/* upb_status *****************************************************************/ | ||
|
||
void upb_status_clear(upb_status *status) { | ||
@@ -37,8 +26,8 @@ const char *upb_status_errmsg(const upb_status *status) { return status->msg; } | ||
void upb_status_seterrmsg(upb_status *status, const char *msg) { | ||
if (!status) return; | ||
status->ok = false; | ||
- strncpy(status->msg, msg, sizeof(status->msg)); | ||
- nullz(status); | ||
+ strncpy(status->msg, msg, UPB_STATUS_MAX_MESSAGE - 1); | ||
+ status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0'; | ||
} | ||
|
||
void upb_status_seterrf(upb_status *status, const char *fmt, ...) { | ||
@@ -52,7 +41,7 @@ void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) { | ||
if (!status) return; | ||
status->ok = false; | ||
_upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args); | ||
- nullz(status); | ||
+ status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0'; | ||
} | ||
|
||
/* upb_alloc ******************************************************************/ |