From 361cb221bdfca6f18f8e2e12b906d327762ab0f4 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 25 Sep 2017 12:20:04 -0400 Subject: [PATCH] Make format_ucs2() not use a variable-length array. Coverity complains (during the build, as a "recoverable" error): "dp.h", line 134: warning #1234: a variable-length array is not allowed inside of a statement expression uint16_t _ucs2buf[(len)]; \ ^ So don't do that. Signed-off-by: Peter Jones --- src/dp.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dp.h b/src/dp.h index 88fbb9b..4f48c49 100644 --- a/src/dp.h +++ b/src/dp.h @@ -131,10 +131,13 @@ format_vendor_helper(char *buf, size_t size, char *label, const_efidp dp) format_helper(format_vendor_helper, buf, size, off, label, dp) #define format_ucs2(buf, size, off, dp_type, str, len) ({ \ - uint16_t _ucs2buf[(len)]; \ - memset(_ucs2buf, '\0', sizeof (_ucs2buf)); \ - memcpy(_ucs2buf, str, sizeof (_ucs2buf) \ - - sizeof (_ucs2buf[0])); \ + uint16_t *_ucs2buf; \ + uint32_t _ucs2size = sizeof(uint16_t) * len; \ + _ucs2buf = alloca(_ucs2size); \ + if (_ucs2buf == NULL) \ + return -1; \ + memset(_ucs2buf, '\0', _ucs2size); \ + memcpy(_ucs2buf, str, _ucs2size - sizeof(uint16_t)); \ unsigned char *_asciibuf; \ _asciibuf = ucs2_to_utf8(_ucs2buf, (len) - 1); \ if (_asciibuf == NULL) \ -- 2.11.0