134 set_value(0); 135 } 136 } 137 138 template <> void DCmdArgument<jlong>::destroy_value() { } 139 140 template <> void DCmdArgument<bool>::parse_value(const char* str, 141 size_t len, TRAPS) { 142 // len is the length of the current token starting at str 143 if (len == 0) { 144 set_value(true); 145 } else { 146 if (len == strlen("true") && strncasecmp(str, "true", len) == 0) { 147 set_value(true); 148 } else if (len == strlen("false") && strncasecmp(str, "false", len) == 0) { 149 set_value(false); 150 } else { 151 ResourceMark rm; 152 153 char* buf = NEW_RESOURCE_ARRAY(char, len + 1); 154 strncpy(buf, str, len); 155 buf[len] = '\0'; 156 Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(), 157 "Boolean parsing error in command argument '%s'. Could not parse: %s.\n", _name, buf); 158 } 159 } 160 } 161 162 template <> void DCmdArgument<bool>::init_value(TRAPS) { 163 if (has_default()) { 164 this->parse_value(_default_string, strlen(_default_string), THREAD); 165 if (HAS_PENDING_EXCEPTION) { 166 fatal("Default string must be parsable"); 167 } 168 } else { 169 set_value(false); 170 } 171 } 172 173 template <> void DCmdArgument<bool>::destroy_value() { } 174 | 134 set_value(0); 135 } 136 } 137 138 template <> void DCmdArgument<jlong>::destroy_value() { } 139 140 template <> void DCmdArgument<bool>::parse_value(const char* str, 141 size_t len, TRAPS) { 142 // len is the length of the current token starting at str 143 if (len == 0) { 144 set_value(true); 145 } else { 146 if (len == strlen("true") && strncasecmp(str, "true", len) == 0) { 147 set_value(true); 148 } else if (len == strlen("false") && strncasecmp(str, "false", len) == 0) { 149 set_value(false); 150 } else { 151 ResourceMark rm; 152 153 char* buf = NEW_RESOURCE_ARRAY(char, len + 1); 154 155 // This code would be warned as "stringop-truncation" by GCC 8 or later. 156 // So we avoid it via PRAGMA_STRINGOP_TRUNCATION_IGNORED macro. 157 PRAGMA_DIAG_PUSH 158 PRAGMA_STRINGOP_TRUNCATION_IGNORED 159 strncpy(buf, str, len); 160 PRAGMA_DIAG_POP 161 162 buf[len] = '\0'; 163 Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(), 164 "Boolean parsing error in command argument '%s'. Could not parse: %s.\n", _name, buf); 165 } 166 } 167 } 168 169 template <> void DCmdArgument<bool>::init_value(TRAPS) { 170 if (has_default()) { 171 this->parse_value(_default_string, strlen(_default_string), THREAD); 172 if (HAS_PENDING_EXCEPTION) { 173 fatal("Default string must be parsable"); 174 } 175 } else { 176 set_value(false); 177 } 178 } 179 180 template <> void DCmdArgument<bool>::destroy_value() { } 181 |