6619271: The -Xprintflags causes the VM to segv

Add null checks

Reviewed-by: jrose, kvn
This commit is contained in:
Tom Rodriguez 2008-04-03 10:20:44 -07:00
parent 1659f11da6
commit 89290f2817

View file

@ -68,6 +68,7 @@ void Flag::print_on(outputStream* st) {
if (is_uintx()) st->print("%-16lu", get_uintx());
if (is_ccstr()) {
const char* cp = get_ccstr();
if (cp != NULL) {
const char* eol;
while ((eol = strchr(cp, '\n')) != NULL) {
char format_buffer[FORMAT_BUFFER_LEN];
@ -81,6 +82,7 @@ void Flag::print_on(outputStream* st) {
}
st->print("%-16s", cp);
}
}
st->print(" %s", kind);
st->cr();
}
@ -94,11 +96,13 @@ void Flag::print_as_flag(outputStream* st) {
st->print("-XX:%s=" UINTX_FORMAT, name, get_uintx());
} else if (is_ccstr()) {
st->print("-XX:%s=", name);
const char* cp = get_ccstr();
if (cp != NULL) {
// Need to turn embedded '\n's back into separate arguments
// Not so efficient to print one character at a time,
// but the choice is to do the transformation to a buffer
// and print that. And this need not be efficient.
for (const char* cp = get_ccstr(); *cp != '\0'; cp += 1) {
for (; *cp != '\0'; cp += 1) {
switch (*cp) {
default:
st->print("%c", *cp);
@ -108,6 +112,7 @@ void Flag::print_as_flag(outputStream* st) {
break;
}
}
}
} else {
ShouldNotReachHere();
}