hrev47847 adds 1 changeset to branch 'master' old head: 219f6c904ad6efb24c736a91ae35d80a0465c6d8 new head: 669e389c33cbdfc134da6943c84cc6dbb92f5b54 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=669e389+%5E219f6c9 ---------------------------------------------------------------------------- 669e389: tools: data_to_source: fix types of generated variables 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 <pdziepak@xxxxxxxxxxx> [ Paweł Dziepak <pdziepak@xxxxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev47847 Commit: 669e389c33cbdfc134da6943c84cc6dbb92f5b54 URL: http://cgit.haiku-os.org/haiku/commit/?id=669e389 Author: Paweł Dziepak <pdziepak@xxxxxxxxxxx> Date: Wed Sep 10 14:13:59 2014 UTC ---------------------------------------------------------------------------- 1 file changed, 5 insertions(+), 6 deletions(-) src/tools/data_to_source.cpp | 11 +++++------ ---------------------------------------------------------------------------- diff --git a/src/tools/data_to_source.cpp b/src/tools/data_to_source.cpp index c1dceb9..e308c67 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 <stddef.h>\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);