diff options
author | Brian Paul <[email protected]> | 2013-09-14 09:52:58 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2013-10-01 10:10:00 -0600 |
commit | ecd155a428ff441071ace8d789e4b89740dd1b58 (patch) | |
tree | 1896f2aef6ed4782a9176a8140f386718f2d84cb /src | |
parent | d2eb281fb2322fd4b73d558e07883ed2f85edf25 (diff) |
mesa: asst. clean-ups in copy_label()
This incorporates Vinson's change to check for a null src pointer as
detected by coverity.
Also, rename the function params to be src/dst, const-qualify src,
and use GL types to match the calling functions. And add some more
comments.
Reviewed-by: Timothy Arceri <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/main/objectlabel.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/mesa/main/objectlabel.c b/src/mesa/main/objectlabel.c index 90d9e09f57d..d9e42cfe4a6 100644 --- a/src/mesa/main/objectlabel.c +++ b/src/mesa/main/objectlabel.c @@ -86,21 +86,38 @@ set_label(struct gl_context *ctx, char **labelPtr, const char *label, /** * Helper for _mesa_GetObjectLabel() and _mesa_GetObjectPtrLabel(). + * \param src the src label (may be null) + * \param dst pointer to dest buffer (may be null) + * \param length returns length of label (may be null) + * \param bufsize size of dst buffer */ static void -copy_label(char **labelPtr, char *label, int *length, int bufSize) +copy_label(const GLchar *src, GLchar *dst, GLsizei *length, GLsizei bufSize) { int labelLen = 0; - if (*labelPtr) - labelLen = strlen(*labelPtr); + /* From http://www.opengl.org/registry/specs/KHR/debug.txt: + * "If <length> is NULL, no length is returned. The maximum number of + * characters that may be written into <label>, including the null + * terminator, is specified by <bufSize>. If no debug label was specified + * for the object then <label> will contain a null-terminated empty string, + * and zero will be returned in <length>. If <label> is NULL and <length> + * is non-NULL then no string will be returned and the length of the label + * will be returned in <length>." + */ - if (label) { - if (bufSize <= labelLen) - labelLen = bufSize-1; + if (src) + labelLen = strlen(src); + + if (dst) { + if (src) { + if (bufSize <= labelLen) + labelLen = bufSize - 1; + + memcpy(dst, src, labelLen); + } - memcpy(label, *labelPtr, labelLen); - label[labelLen] = '\0'; + dst[labelLen] = '\0'; } if (length) @@ -243,7 +260,7 @@ _mesa_GetObjectLabel(GLenum identifier, GLuint name, GLsizei bufSize, if (!labelPtr) return; - copy_label(labelPtr, label, length, bufSize); + copy_label(*labelPtr, label, length, bufSize); } void GLAPIENTRY @@ -278,5 +295,5 @@ _mesa_GetObjectPtrLabel(const void *ptr, GLsizei bufSize, GLsizei *length, labelPtr = &syncObj->Label; - copy_label(labelPtr, label, length, bufSize); + copy_label(*labelPtr, label, length, bufSize); } |