src/fcint.h | 3 +++ src/fcname.c | 30 ++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) New commits: commit 65c7427c019c1cb7c621e6be87fb298564d45f51 Author: Akira TAGOH <akira@xxxxxxxxx> Date: Fri Nov 30 07:03:54 2018 +0000 Warn when constant name is used for unexpected object This fixes the sort of weird things like `fc-match :size=rgb` done without any errors. This might be annoyed but the error messages should helps to fix an application bug or suggest more useful constant names to fontconfig. Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/137 diff --git a/src/fcint.h b/src/fcint.h index a9d075a..d473955 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -1022,6 +1022,9 @@ enum { }; FcPrivate FcBool +FcNameConstantWithObjectCheck (const FcChar8 *string, const char *object, int *result); + +FcPrivate FcBool FcNameBool (const FcChar8 *v, FcBool *result); FcPrivate FcBool diff --git a/src/fcname.c b/src/fcname.c index 711bb9b..041d6d6 100644 --- a/src/fcname.c +++ b/src/fcname.c @@ -242,6 +242,24 @@ FcNameConstant (const FcChar8 *string, int *result) } FcBool +FcNameConstantWithObjectCheck (const FcChar8 *string, const char *object, int *result) +{ + const FcConstant *c; + + if ((c = FcNameGetConstant(string))) + { + if (strcmp (c->object, object) != 0) + { + fprintf (stderr, "Fontconfig error: Unexpected constant name `%s' used for object `%s': should be `%s'\n", string, object, c->object); + return FcFalse; + } + *result = c->value; + return FcTrue; + } + return FcFalse; +} + +FcBool FcNameBool (const FcChar8 *v, FcBool *result) { char c0, c1; @@ -287,7 +305,7 @@ FcNameBool (const FcChar8 *v, FcBool *result) } static FcValue -FcNameConvert (FcType type, FcChar8 *string) +FcNameConvert (FcType type, const char *object, FcChar8 *string) { FcValue v; FcMatrix m; @@ -297,7 +315,7 @@ FcNameConvert (FcType type, FcChar8 *string) v.type = type; switch ((int) v.type) { case FcTypeInteger: - if (!FcNameConstant (string, &v.u.i)) + if (!FcNameConstantWithObjectCheck (string, object, &v.u.i)) v.u.i = atoi ((char *) string); break; case FcTypeString: @@ -338,8 +356,8 @@ FcNameConvert (FcType type, FcChar8 *string) ec = malloc (len + 1); if (sc && ec && sscanf ((char *) string, "[%s %[^]]]", sc, ec) == 2) { - if (FcNameConstant ((const FcChar8 *) sc, &si) && - FcNameConstant ((const FcChar8 *) ec, &ei)) + if (FcNameConstantWithObjectCheck ((const FcChar8 *) sc, object, &si) && + FcNameConstantWithObjectCheck ((const FcChar8 *) ec, object, &ei)) v.u.r = FcRangeCreateDouble (si, ei); else goto bail1; @@ -348,7 +366,7 @@ FcNameConvert (FcType type, FcChar8 *string) { bail1: v.type = FcTypeDouble; - if (FcNameConstant (string, &si)) + if (FcNameConstantWithObjectCheck (string, object, &si)) { v.u.d = (double) si; } else { @@ -461,7 +479,7 @@ FcNameParse (const FcChar8 *name) name = FcNameFindNext (name, ":,", save, &delim); if (t) { - v = FcNameConvert (t->type, save); + v = FcNameConvert (t->type, t->object, save); if (!FcPatternAdd (pat, t->object, v, FcTrue)) { FcValueDestroy (v); _______________________________________________ Fontconfig mailing list Fontconfig@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/fontconfig