Skip to content

Commit

Permalink
Merge pull request #292 from jfkthame/error-message-invalid-tag
Browse files Browse the repository at this point in the history
Show invalid table tags as hex in error messages.
  • Loading branch information
khaledhosny authored Jan 2, 2025
2 parents ea789e2 + 29452f9 commit 0dd1b11
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit 0dd1b11

Please sign in to comment.