Skip to content

Commit c7e046c

Browse files
authored
Fix gcc warnings in appendLibId. (KhronosGroup#626)
1 parent 021df76 commit c7e046c

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

lib/writer2.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ appendLibId(ktxHashList* head, ktxHashListEntry* writerEntry)
115115
const char* libVer;
116116
const char libIdIntro[] = " / libktx ";
117117
size_t idLen, libIdLen;
118+
118119
if (writerEntry) {
119120
ktx_uint32_t len;
120121
result = ktxHashListEntry_GetValue(writerEntry, &len, (void**)&id);
@@ -123,25 +124,22 @@ appendLibId(ktxHashList* head, ktxHashListEntry* writerEntry)
123124
id = "Unidentified app";
124125
idLen = 17;
125126
}
127+
126128
// strnstr needed because KTXwriter values may not be NUL terminated.
127129
if (strnstr(id, "__default__", idLen) != NULL) {
128130
libVer = STR(LIBKTX_DEFAULT_VERSION);
129131
} else {
130132
libVer = STR(LIBKTX_VERSION);
131133
}
132-
// sizeof(libIdIntro) includes space for the terminating NUL which we will
134+
// sizeof(libIdIntro) includes space for its terminating NUL which we will
133135
// overwrite so no need for +1 after strlen.
134136
libIdLen = sizeof(libIdIntro) + (ktx_uint32_t)strlen(libVer);
135137
char* libId = malloc(libIdLen);
136138
if (!libId)
137139
return KTX_OUT_OF_MEMORY;
138-
// &libIdIntro[0] instead of libIdIntro is to workaround a gcc warning
139-
// that I'm passing the same thing to sizeof as to the src
140-
// parameter (i.e. I'm requesting the sizeof a pointer).
141-
// Actually libIdIntro is an array of char not a pointer. Looks
142-
// like a gcc bug.
143-
strncpy(libId, &libIdIntro[0], sizeof(libIdIntro));
144-
strncpy(&libId[sizeof(libIdIntro)-1], libVer, strlen(libVer) + 1);
140+
strncpy(libId, libIdIntro, libIdLen);
141+
strncpy(&libId[sizeof(libIdIntro)-1], libVer,
142+
libIdLen-(sizeof(libIdIntro)-1));
145143

146144
if (strnstr(id, libId, idLen) != NULL) {
147145
// This lib id is already in the writer value.

0 commit comments

Comments
 (0)