120 strncpy(buf, str, len); 121 buf[len] = '\0'; 122 Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(), 123 "Integer parsing error in command argument '%s'. Could not parse: %s.\n", _name, buf); 124 } 125 } 126 127 template <> void DCmdArgument<jlong>::init_value(TRAPS) { 128 if (has_default()) { 129 this->parse_value(_default_string, strlen(_default_string), THREAD); 130 if (HAS_PENDING_EXCEPTION) { 131 fatal("Default string must be parseable"); 132 } 133 } else { 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 175 template <> void DCmdArgument<char*>::parse_value(const char* str, 176 size_t len, TRAPS) { 177 if (str == NULL) { 178 _value = NULL; 179 } else { 180 _value = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); | 120 strncpy(buf, str, len); 121 buf[len] = '\0'; 122 Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(), 123 "Integer parsing error in command argument '%s'. Could not parse: %s.\n", _name, buf); 124 } 125 } 126 127 template <> void DCmdArgument<jlong>::init_value(TRAPS) { 128 if (has_default()) { 129 this->parse_value(_default_string, strlen(_default_string), THREAD); 130 if (HAS_PENDING_EXCEPTION) { 131 fatal("Default string must be parseable"); 132 } 133 } else { 134 set_value(0); 135 } 136 } 137 138 template <> void DCmdArgument<jlong>::destroy_value() { } 139 140 PRAGMA_DIAG_PUSH 141 PRAGMA_STRINGOP_TRUNCATION_IGNORED 142 template <> void DCmdArgument<bool>::parse_value(const char* str, 143 size_t len, TRAPS) { 144 // len is the length of the current token starting at str 145 if (len == 0) { 146 set_value(true); 147 } else { 148 if (len == strlen("true") && strncasecmp(str, "true", len) == 0) { 149 set_value(true); 150 } else if (len == strlen("false") && strncasecmp(str, "false", len) == 0) { 151 set_value(false); 152 } else { 153 ResourceMark rm; 154 155 char* buf = NEW_RESOURCE_ARRAY(char, len + 1); 156 157 // This code would be warned as "stringop-truncatino" by GCC 8 or later. 158 // So we avoid it via PRAGMA_STRINGOP_TRUNCATION_IGNORED macro. 159 strncpy(buf, str, len); 160 161 buf[len] = '\0'; 162 Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(), 163 "Boolean parsing error in command argument '%s'. Could not parse: %s.\n", _name, buf); 164 } 165 } 166 } 167 PRAGMA_DIAG_POP 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 182 template <> void DCmdArgument<char*>::parse_value(const char* str, 183 size_t len, TRAPS) { 184 if (str == NULL) { 185 _value = NULL; 186 } else { 187 _value = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); |