enum mesa_debug_type type;
GLuint id;
enum mesa_debug_severity severity;
+ /* length as given by the user - if message was explicitly null terminated,
+ * length can be negative */
GLsizei length;
GLcharARB *message;
};
enum mesa_debug_severity severity,
GLsizei len, const char *buf)
{
+ GLsizei length = len;
+
assert(!msg->message && !msg->length);
- msg->message = malloc(len+1);
+ if (length < 0)
+ length = strlen(buf);
+
+ msg->message = malloc(length+1);
if (msg->message) {
- (void) strncpy(msg->message, buf, (size_t)len);
- msg->message[len] = '\0';
+ (void) strncpy(msg->message, buf, (size_t)length);
+ msg->message[length] = '\0';
- msg->length = len+1;
+ msg->length = len;
msg->source = source;
msg->type = type;
msg->id = id;
/* malloc failed! */
msg->message = out_of_memory;
- msg->length = strlen(out_of_memory)+1;
+ msg->length = -1;
msg->source = MESA_DEBUG_SOURCE_OTHER;
msg->type = MESA_DEBUG_TYPE_ERROR;
msg->id = oom_msg_id;
GLint nextEmpty;
struct gl_debug_message *emptySlot;
- assert(len >= 0 && len < MAX_DEBUG_MESSAGE_LENGTH);
+ assert(len < MAX_DEBUG_MESSAGE_LENGTH);
if (log->NumMessages == MAX_DEBUG_LOGGED_MESSAGES)
return;
if (!validate_params(ctx, INSERT, callerstr, source, type, severity))
return; /* GL_INVALID_ENUM */
- if (length < 0)
- length = strlen(buf);
if (!validate_length(ctx, callerstr, length, buf))
return; /* GL_INVALID_VALUE */
for (ret = 0; ret < count; ret++) {
const struct gl_debug_message *msg = debug_fetch_message(debug);
+ GLsizei len;
if (!msg)
break;
- if (logSize < msg->length && messageLog != NULL)
+ len = msg->length;
+ if (len < 0)
+ len = strlen(msg->message);
+
+ if (logSize < len+1 && messageLog != NULL)
break;
if (messageLog) {
- assert(msg->message[msg->length-1] == '\0');
- (void) strncpy(messageLog, msg->message, (size_t)msg->length);
+ assert(msg->message[len] == '\0');
+ (void) strncpy(messageLog, msg->message, (size_t)len+1);
- messageLog += msg->length;
- logSize -= msg->length;
+ messageLog += len+1;
+ logSize -= len+1;
}
if (lengths)
- *lengths++ = msg->length;
+ *lengths++ = len+1;
if (severities)
*severities++ = debug_severity_enums[msg->severity];
if (sources)
return;
}
- if (length < 0)
- length = strlen(message);
if (!validate_length(ctx, callerstr, length, message))
return; /* GL_INVALID_VALUE */