JPEG2000Translator: Fix -Werror warnings

This fix is for ticket #9460 to potentially enable -Werror for JPEG2000Translator.
Original warning: 'char* strncpy(char*, const char*, size_t)' specified bound equals destination size [-Wstringop-truncation]

- Replaced several occurrences of same string with existing constant.
- Use strcmp instead of strncmp as one string is guaranteed to be null-terminated
- Replace strncpy use with strlcpy as seen in other code places.

Change-Id: I5e7ed0de10dc40447a64fe77a7909af577e128ac
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4472
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Franck LeCodeur
2021-09-22 07:27:07 +00:00
committed by Jérôme Duval
parent 158b8fdab2
commit e5928728d5
@@ -1242,15 +1242,15 @@ JP2Translator::PopulateInfoFromFormat(translator_info* info,
info->group = formats[i].group;
info->quality = formats[i].quality;
info->capability = formats[i].capability;
if (strncmp(formats[i].name,
"Be Bitmap Format (JPEG2000Translator)",
sizeof("Be Bitmap Format (JPEG2000Translator)")) == 0)
strncpy(info->name,
B_TRANSLATE("Be Bitmap Format (JPEG2000Translator)"),
if (strcmp(formats[i].name, B_TRANSLATOR_BITMAP_DESCRIPTION)
== 0) {
strlcpy(info->name,
B_TRANSLATE(B_TRANSLATOR_BITMAP_DESCRIPTION),
sizeof(info->name));
else
strncpy(info->name, formats[i].name, sizeof(info->name));
strncpy(info->MIME, formats[i].MIME, sizeof(info->MIME));
} else {
strlcpy(info->name, formats[i].name, sizeof(info->name));
}
strlcpy(info->MIME, formats[i].MIME, sizeof(info->MIME));
return B_OK;
}
}