зеркало из https://github.com/github/ruby.git
[ruby/prism] check_string() should always return a valid C string
* Otherwise it is invalid e.g. to call strlen() to the result, or to assume the argument was a string. * All callers are already checking for nil before. https://github.com/ruby/prism/commit/8197be883e
This commit is contained in:
Родитель
5228d349d9
Коммит
b8baf3f3ee
|
@ -42,17 +42,11 @@ ID rb_id_source_for;
|
|||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Check if the given VALUE is a string. If it's nil, then return NULL. If it's
|
||||
* not a string, then raise a type error. Otherwise return the VALUE as a C
|
||||
* string.
|
||||
* Check if the given VALUE is a string. If it's not a string, then raise a
|
||||
* TypeError. Otherwise return the VALUE as a C string.
|
||||
*/
|
||||
static const char *
|
||||
check_string(VALUE value) {
|
||||
// If the value is nil, then we don't need to do anything.
|
||||
if (NIL_P(value)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check if the value is a string. If it's not, then raise a type error.
|
||||
if (!RB_TYPE_P(value, T_STRING)) {
|
||||
rb_raise(rb_eTypeError, "wrong argument type %" PRIsVALUE " (expected String)", rb_obj_class(value));
|
||||
|
|
Загрузка…
Ссылка в новой задаче