/* * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
void GenDCmdArgument::read_value(constchar* str, size_t len, TRAPS) { /* NOTE:Some argument types doesn't require a value, * for instance boolean arguments: "enableFeatureX". is * equivalent to "enableFeatureX=true". In these cases, * str will be null. This is perfectly valid. * All argument types must perform null checks on str.
*/
if (is_set() && !allow_multiple()) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Duplicates in diagnostic command arguments\n");
}
parse_value(str, len, CHECK);
set_is_set(true);
}
void GenDCmdArgument::to_string(StringArrayArgument* f, char* buf, size_t len) const { int length = f->array()->length();
size_t written = 0;
buf[0] = 0; for (int i = 0; i < length; i++) { char* next_str = f->array()->at(i);
size_t next_size = strlen(next_str); //Check if there's room left to write next element if (written + next_size > len) { return;
} //Actually write element
strcat(buf, next_str);
written += next_size; //Check if there's room left for the comma if (i < length-1 && len - written > 0) {
strcat(buf, ",");
}
}
}
template <> void DCmdArgument<bool>::parse_value(constchar* str,
size_t len, TRAPS) { // len is the length of the current token starting at str if (len == 0) {
set_value(true);
} else { if (len == strlen("true") && strncasecmp(str, "true", len) == 0) {
set_value(true);
} elseif (len == strlen("false") && strncasecmp(str, "false", len) == 0) {
set_value(false);
} else {
ResourceMark rm;
char* buf = NEW_RESOURCE_ARRAY(char, len + 1);
PRAGMA_DIAG_PUSH
PRAGMA_STRINGOP_TRUNCATION_IGNORED // This code can incorrectly cause a "stringop-truncation" warning with gcc
strncpy(buf, str, len);
PRAGMA_DIAG_POP
buf[len] = '\0';
Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(), "Boolean parsing error in command argument '%s'. Could not parse: %s.\n", _name, buf);
}
}
}
template <> void DCmdArgument<bool>::init_value(TRAPS) { if (has_default()) {
this->parse_value(_default_string, strlen(_default_string), THREAD); if (HAS_PENDING_EXCEPTION) {
fatal("Default string must be parsable");
}
} else {
set_value(false);
}
}
template <> void DCmdArgument<NanoTimeArgument>::parse_value(constchar* str,
size_t len, TRAPS) { if (str == NULL) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Integer parsing error nanotime value: syntax error, value is null\n");
}
int argc = sscanf(str, JLONG_FORMAT, &_value._time); if (argc != 1) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Integer parsing error nanotime value: syntax error\n");
}
size_t idx = 0; while(idx < len && isdigit(str[idx])) {
idx++;
} if (idx == len) { // only accept missing unit if the value is 0 if (_value._time != 0) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Integer parsing error nanotime value: unit required\n");
} else {
_value._nanotime = 0;
strcpy(_value._unit, "ns"); return;
}
} elseif(len - idx > 2) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Integer parsing error nanotime value: illegal unit\n");
} else {
strncpy(_value._unit, &str[idx], len - idx); /*Write an extra null termination. This is safe because _value._unit * is declared as char[3], and length is checked to be not larger than * two above. Also, this is necessary, since length might be 1, and the * default value already in the string is ns, which is two chars.
*/
_value._unit[len-idx] = '\0';
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.