Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion include/upipe/udict.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ enum udict_type {
/** p.cea_708 */
UDICT_TYPE_PIC_CEA_708,
/** p.bar_data */
UDICT_TYPE_PIC_BAR_DATA
UDICT_TYPE_PIC_BAR_DATA,

/** end of the shorthand types, not a type itself */
UDICT_TYPE_SHORTHAND_END
};

/** @This defines standard commands which udict modules may implement. */
Expand Down
4 changes: 2 additions & 2 deletions lib/upipe/udict_inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ static int udict_inline_dup(struct udict *udict, struct udict **new_udict_p)
static const struct inline_shorthand *
udict_inline_shorthand(enum udict_type type)
{
if (unlikely(type > UDICT_TYPE_SHORTHAND + 1 + sizeof(inline_shorthands) /
sizeof(struct inline_shorthand)))
if (unlikely(type > UDICT_TYPE_SHORTHAND + sizeof(inline_shorthands) /
sizeof(struct inline_shorthand)))
return NULL;
return &inline_shorthands[type - UDICT_TYPE_SHORTHAND - 1];
}
Expand Down
18 changes: 18 additions & 0 deletions tests/udict_inline_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,24 @@ int main(int argc, char **argv)
udict_free(udict2);
}

{
/* every shorthand type has a name, and the end of the shorthand
* types is rejected rather than read past the table of shorthands */
struct udict *udict = udict_alloc(mgr, 0);
assert(udict != NULL);
const char *name;
enum udict_type base;
for (int type = UDICT_TYPE_SHORTHAND + 1;
type < UDICT_TYPE_SHORTHAND_END; type++) {
ubase_assert(udict_name(udict, (enum udict_type)type, &name,
&base));
assert(name != NULL && base < UDICT_TYPE_SHORTHAND);
}
ubase_nassert(udict_name(udict, UDICT_TYPE_SHORTHAND_END, &name,
&base));
udict_free(udict);
}

udict_mgr_release(mgr);

umem_mgr_release(umem_mgr);
Expand Down
Loading