1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

tttrace: Fix bad usage of va_arg with enums

Enums may be represented with a smaller type than int; however, they are
automatically promoted to int when passed in va_arg lists, just as
short, char, etc. are. GCC thus "knows" that you never want to call
va_arg with an enum type, and instead inserts an abort.
This commit is contained in:
Frederic Koehler 2012-08-11 17:15:39 -04:00 committed by Jon Trulson
parent 71f3ed16f8
commit 5ad7a83985

View file

@ -384,57 +384,64 @@ _Tt_trace::entry(
while (num_args--) { while (num_args--) {
c = *preview++; c = *preview++;
switch (c) { switch (c) {
/* For the "type" to va_arg, we must pass int!
* If we try to use the real type (e.g. Tt_address, etc.)
* gcc will complain loudly and cause the program to abort here.
* This is because the size of enums can be less than that of int,
* and in va_args anything smaller than an int is "promoted"
* into an int.
*/
case ADDRESS : { case ADDRESS : {
Tt_address s; Tt_address s;
s = va_arg(ap, Tt_address); s = (Tt_address) va_arg(ap, int);
**_pstream << _tt_enumname(s); **_pstream << _tt_enumname(s);
} break; } break;
case STATE: { case STATE: {
Tt_state s; Tt_state s;
s = va_arg(ap, Tt_state); s = (Tt_state) va_arg(ap, int);
**_pstream << _tt_enumname(s); **_pstream << _tt_enumname(s);
} break; } break;
case DISPOSITION: { case DISPOSITION: {
Tt_disposition s; Tt_disposition s;
s = va_arg(ap, Tt_disposition); s = (Tt_disposition) va_arg(ap, int);
**_pstream << _tt_enumname(s); **_pstream << _tt_enumname(s);
} break; } break;
case CLASS: { case CLASS: {
Tt_class s; Tt_class s;
s = va_arg(ap, Tt_class); s = (Tt_class) va_arg(ap, int);
**_pstream << _tt_enumname(s); **_pstream << _tt_enumname(s);
} break; } break;
case MODE: { case MODE: {
Tt_mode s; Tt_mode s;
s = va_arg(ap, Tt_mode); s = (Tt_mode) va_arg(ap, int);
**_pstream << _tt_enumname(s); **_pstream << _tt_enumname(s);
} break; } break;
case CATEGORY: { case CATEGORY: {
Tt_category s; Tt_category s;
s = va_arg(ap, Tt_category); s = (Tt_category) va_arg(ap, int);
**_pstream << _tt_enumname(s); **_pstream << _tt_enumname(s);
} break; } break;
case SCOPE: { case SCOPE: {
Tt_scope s; Tt_scope s;
s = va_arg(ap, Tt_scope); s = (Tt_scope) va_arg(ap, int);
**_pstream << _tt_enumname(s); **_pstream << _tt_enumname(s);
} break; } break;
case FEATURE: { case FEATURE: {
Tt_feature f; Tt_feature f;
f = va_arg(ap, Tt_feature); f = (Tt_feature) va_arg(ap, int);
**_pstream << _tt_enumname(f); **_pstream << _tt_enumname(f);
} break; } break;
case AUDIT_STATUS: { case AUDIT_STATUS: {
Tt_status status; Tt_status status;
status = va_arg(ap, Tt_status); status = (Tt_status) va_arg(ap, int);
**_pstream << status; **_pstream << status;
} break; } break;