From 669e389c33cbdfc134da6943c84cc6dbb92f5b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dziepak?= Date: Wed, 10 Sep 2014 16:13:59 +0200 Subject: [PATCH] tools: data_to_source: fix types of generated variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both data array and its size should be constant so that GCC can do as much as possible at compile time and it is safe to use them in static assertions. This patch also changes the type of size constant to size_t which more appropriate and uses sizeof() to determine the size of the array. Fixes build breakage introduced in e547662664d88e5ee79048bd00ad8eefa45e7074. Signed-off-by: Paweł Dziepak --- src/tools/data_to_source.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/tools/data_to_source.cpp b/src/tools/data_to_source.cpp index c1dceb95e9..e308c673ac 100644 --- a/src/tools/data_to_source.cpp +++ b/src/tools/data_to_source.cpp @@ -63,10 +63,11 @@ main(int argc, const char* const* argv) unsigned char buffer[kBufferSize]; char lineBuffer[128]; - sprintf(lineBuffer, "unsigned char %s[] = {\n", dataVarName); + sprintf(lineBuffer, "#include \n"); + write_string(outFD, lineBuffer); + sprintf(lineBuffer, "const unsigned char %s[] = {\n", dataVarName); write_string(outFD, lineBuffer); - off_t dataSize = 0; off_t offset = 0; char* lineBufferEnd = lineBuffer; *lineBufferEnd = '\0'; @@ -81,8 +82,6 @@ main(int argc, const char* const* argv) if (bytesRead == 0) break; - dataSize += bytesRead; - // write lines for (int i = 0; i < bytesRead; i++, offset++) { if (offset % kCharsPerLine == 0) { @@ -109,8 +108,8 @@ main(int argc, const char* const* argv) } // close the braces and write the size variable - sprintf(lineBuffer, "};\nlong long %s = %lldLL;\n", sizeVarName, - (long long)dataSize); + sprintf(lineBuffer, "};\nconst size_t %s = sizeof(%s);\n", sizeVarName, + dataVarName); write_string(outFD, lineBuffer); close(inFD);