diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-05-18 17:50:44 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-05-18 17:51:59 +0400 |
commit | 2a49bf35f08752cadf998a05867c4244378b4c57 (patch) | |
tree | 9910a962886a80301d5bf02d66ae354046819548 /source/blender/blenkernel | |
parent | 07e8096c63a35af3331aae7781643ca103dd1bdf (diff) |
Add ARRAY_SIZE macro to check fixed size arrays
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/idcode.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c index c987e0b67cb..2e201a0b8e8 100644 --- a/source/blender/blenkernel/intern/idcode.c +++ b/source/blender/blenkernel/intern/idcode.c @@ -84,12 +84,11 @@ static IDType idtypes[] = { { ID_WO, "World", "worlds", IDTYPE_FLAGS_ISLINKABLE }, { ID_WM, "WindowManager", "window_managers", 0 }, }; -static int nidtypes = sizeof(idtypes) / sizeof(idtypes[0]); static IDType *idtype_from_name(const char *str) { - int i = nidtypes; - + int i = ARRAY_SIZE(idtypes); + while (i--) { if (STREQ(str, idtypes[i].name)) { return &idtypes[i]; @@ -100,8 +99,8 @@ static IDType *idtype_from_name(const char *str) } static IDType *idtype_from_code(int code) { - int i = nidtypes; - + int i = ARRAY_SIZE(idtypes); + while (i--) if (code == idtypes[i].code) return &idtypes[i]; @@ -182,5 +181,5 @@ const char *BKE_idcode_to_name_plural(int code) */ int BKE_idcode_iter_step(int *index) { - return (*index < nidtypes) ? idtypes[(*index)++].code : 0; + return (*index < ARRAY_SIZE(idtypes)) ? idtypes[(*index)++].code : 0; } |