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 e547662664.
Signed-off-by: Paweł Dziepak <[email protected]>
This commit is contained in:
@@ -63,10 +63,11 @@ main(int argc, const char* const* argv)
|
|||||||
unsigned char buffer[kBufferSize];
|
unsigned char buffer[kBufferSize];
|
||||||
char lineBuffer[128];
|
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);
|
write_string(outFD, lineBuffer);
|
||||||
|
|
||||||
off_t dataSize = 0;
|
|
||||||
off_t offset = 0;
|
off_t offset = 0;
|
||||||
char* lineBufferEnd = lineBuffer;
|
char* lineBufferEnd = lineBuffer;
|
||||||
*lineBufferEnd = '\0';
|
*lineBufferEnd = '\0';
|
||||||
@@ -81,8 +82,6 @@ main(int argc, const char* const* argv)
|
|||||||
if (bytesRead == 0)
|
if (bytesRead == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
dataSize += bytesRead;
|
|
||||||
|
|
||||||
// write lines
|
// write lines
|
||||||
for (int i = 0; i < bytesRead; i++, offset++) {
|
for (int i = 0; i < bytesRead; i++, offset++) {
|
||||||
if (offset % kCharsPerLine == 0) {
|
if (offset % kCharsPerLine == 0) {
|
||||||
@@ -109,8 +108,8 @@ main(int argc, const char* const* argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// close the braces and write the size variable
|
// close the braces and write the size variable
|
||||||
sprintf(lineBuffer, "};\nlong long %s = %lldLL;\n", sizeVarName,
|
sprintf(lineBuffer, "};\nconst size_t %s = sizeof(%s);\n", sizeVarName,
|
||||||
(long long)dataSize);
|
dataVarName);
|
||||||
write_string(outFD, lineBuffer);
|
write_string(outFD, lineBuffer);
|
||||||
|
|
||||||
close(inFD);
|
close(inFD);
|
||||||
|
|||||||
Reference in New Issue
Block a user