comparison src/SDL_error.c @ 1172:f69f4d25fb20

Don't crash if a NULL is passed for a "%s" parameter to SDL_SetError(), instead replace it with the string "(null)", like glibc's printf() would do.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 17 Nov 2005 03:04:47 +0000
parents b8d311d90021
children c9b51268668f
comparison
equal deleted inserted replaced
1171:f84c6f1397cd 1172:f69f4d25fb20
106 va_arg(ap, void *); 106 va_arg(ap, void *);
107 break; 107 break;
108 case 's': 108 case 's':
109 { 109 {
110 int index = error->argc; 110 int index = error->argc;
111 strncpy((char *)error->args[index].buf, 111 char *str = va_arg(ap, char *);
112 va_arg(ap, char *), ERR_MAX_STRLEN); 112 if (str == NULL)
113 str = "(null)";
114 strncpy((char *)error->args[index].buf, str, ERR_MAX_STRLEN);
113 error->args[index].buf[ERR_MAX_STRLEN-1] = 0; 115 error->args[index].buf[ERR_MAX_STRLEN-1] = 0;
114 error->argc++; 116 error->argc++;
115 } 117 }
116 break; 118 break;
117 default: 119 default: