From 29ce809772d38c89610d6ef25dde9228c2bfabc3 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 15 Jun 2019 21:38:21 -0400 Subject: [PATCH] And FINALLY fixed the NULL name error in uiRegisterControlType(). --- common/controls.c | 4 ++++ doc/controls.md | 2 +- test/controls_errors.cpp | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/common/controls.c b/common/controls.c index a52a7584..483fec4f 100644 --- a/common/controls.c +++ b/common/controls.c @@ -48,6 +48,10 @@ uint32_t uiRegisterControlType(const char *name, const uiControlVtable *vtable, if (!uiprivCheckInitializedAndThread()) return 0; + if (name == NULL) { + uiprivProgrammerErrorNullPointer("name", uiprivFunc); + return 0; + } if (vtable == NULL) { uiprivProgrammerErrorNullPointer("uiControlVtable", uiprivFunc); return 0; diff --git a/doc/controls.md b/doc/controls.md index 4d010740..07b92238 100644 --- a/doc/controls.md +++ b/doc/controls.md @@ -47,7 +47,7 @@ uint32_t uiRegisterControlType(const char *name, const uiControlVtable *vtable, `uiRegisterControlType()` registers a new `uiControl` type with the given vtables and returns its ID as passed to `uiNewControl()`. `implDataSize` is the size of the implementation data struct that is created by `uiNewControl()`. -Each type has a name, passed in the `name` parameter. The type name is only used for debugging and error reporting purposes. The type name is copied into libui-internal memory; the `name` pointer passed to `uiRegisterControlType()` is not used after it returns. +Each type has a name, passed in the `name` parameter. The type name is only used for debugging and error reporting purposes. The type name is copied into libui-internal memory; the `name` pointer passed to `uiRegisterControlType()` is not used after it returns. It is a programmer error to specify `NULL` for `name`. (TODO anything else? Empty string? Duplicate name?) `uiControlVtable` describes the functions of a `uiControl` common between platforms, and is discussed on this page. `uiControlOSVtable` describes functionst hat vary from OS to OS, and are described in the respective OS-specific uiControl implementation pages. The two vtables are copied into libui-internal memory; the vtable pointers passed to `uiRegisterControlType()` are not used after it returns. diff --git a/test/controls_errors.cpp b/test/controls_errors.cpp index 9923a0dc..599068bb 100644 --- a/test/controls_errors.cpp +++ b/test/controls_errors.cpp @@ -7,7 +7,7 @@ static const struct checkErrorCase cases[] = { [](void) { uiRegisterControlType(NULL, NULL, NULL, 0); }, - "uiRegisterControlType(): invalid null pointer for uiControlOSVtable", + "uiRegisterControlType(): invalid null pointer for name", }, { "uiRegisterControlType() with NULL vtable",