Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show invalid table tags as hex in error messages. #292

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/ots.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,18 @@ bool CheckTag(uint32_t tag_value) {

namespace {

#define OTS_MSG_TAG_(level,otf_,msg_,tag_) \
(OTS_MESSAGE_(level,otf_,"%c%c%c%c: %s", OTS_UNTAG(tag_), msg_), false)
// ots_msg_tag emits the tag as hex if it is not valid, to avoid putting NUL or
// other non-printables into the message string.
static inline void ots_msg_tag(int level, const ots::FontFile* otf, const char* msg, uint32_t tag) {
if (ots::CheckTag(tag)) {
OTS_MESSAGE_(level, otf, "%c%c%c%c: %s", OTS_UNTAG(tag), msg);
} else {
OTS_MESSAGE_(level, otf, "<%08X>: %s", tag, msg);
}
}

// Generate a message with or without a table tag, when 'header' is the FontFile pointer
#define OTS_FAILURE_MSG_TAG(msg_,tag_) OTS_MSG_TAG_(0, header, msg_, tag_)
#define OTS_FAILURE_MSG_TAG(msg_,tag_) (ots_msg_tag(0, header, msg_, tag_), false)
#define OTS_FAILURE_MSG_HDR(...) OTS_FAILURE_MSG_(header, __VA_ARGS__)
#define OTS_WARNING_MSG_HDR(...) OTS_WARNING_MSG_(header, __VA_ARGS__)

Expand Down
Loading