Merge pull request #66185 from touilleMan/gdextension-no-error-log-outofindex-operator-index

Make *_operator_index in gdnative_interface not logging an error if called with an out-of-bound index
This commit is contained in:
Emmanuel Leblond 2023-05-13 21:43:54 +02:00 committed by GitHub
commit ffd32a244b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -680,13 +680,17 @@ static GDExtensionInt gdextension_string_to_wide_chars(GDExtensionConstStringPtr
static char32_t *gdextension_string_operator_index(GDExtensionStringPtr p_self, GDExtensionInt p_index) { static char32_t *gdextension_string_operator_index(GDExtensionStringPtr p_self, GDExtensionInt p_index) {
String *self = (String *)p_self; String *self = (String *)p_self;
ERR_FAIL_INDEX_V(p_index, self->length() + 1, nullptr); if (unlikely(p_index < 0 || p_index >= self->length() + 1)) {
return nullptr;
}
return &self->ptrw()[p_index]; return &self->ptrw()[p_index];
} }
static const char32_t *gdextension_string_operator_index_const(GDExtensionConstStringPtr p_self, GDExtensionInt p_index) { static const char32_t *gdextension_string_operator_index_const(GDExtensionConstStringPtr p_self, GDExtensionInt p_index) {
const String *self = (const String *)p_self; const String *self = (const String *)p_self;
ERR_FAIL_INDEX_V(p_index, self->length() + 1, nullptr); if (unlikely(p_index < 0 || p_index >= self->length() + 1)) {
return nullptr;
}
return &self->ptr()[p_index]; return &self->ptr()[p_index];
} }
@ -747,121 +751,161 @@ static int64_t gdextension_worker_thread_pool_add_native_task(GDExtensionObjectP
static uint8_t *gdextension_packed_byte_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { static uint8_t *gdextension_packed_byte_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
PackedByteArray *self = (PackedByteArray *)p_self; PackedByteArray *self = (PackedByteArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return &self->ptrw()[p_index]; return &self->ptrw()[p_index];
} }
static const uint8_t *gdextension_packed_byte_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) { static const uint8_t *gdextension_packed_byte_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
const PackedByteArray *self = (const PackedByteArray *)p_self; const PackedByteArray *self = (const PackedByteArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return &self->ptr()[p_index]; return &self->ptr()[p_index];
} }
static GDExtensionTypePtr gdextension_packed_color_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { static GDExtensionTypePtr gdextension_packed_color_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
PackedColorArray *self = (PackedColorArray *)p_self; PackedColorArray *self = (PackedColorArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return (GDExtensionTypePtr)&self->ptrw()[p_index]; return (GDExtensionTypePtr)&self->ptrw()[p_index];
} }
static GDExtensionTypePtr gdextension_packed_color_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) { static GDExtensionTypePtr gdextension_packed_color_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
const PackedColorArray *self = (const PackedColorArray *)p_self; const PackedColorArray *self = (const PackedColorArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return (GDExtensionTypePtr)&self->ptr()[p_index]; return (GDExtensionTypePtr)&self->ptr()[p_index];
} }
static float *gdextension_packed_float32_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { static float *gdextension_packed_float32_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
PackedFloat32Array *self = (PackedFloat32Array *)p_self; PackedFloat32Array *self = (PackedFloat32Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return &self->ptrw()[p_index]; return &self->ptrw()[p_index];
} }
static const float *gdextension_packed_float32_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) { static const float *gdextension_packed_float32_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
const PackedFloat32Array *self = (const PackedFloat32Array *)p_self; const PackedFloat32Array *self = (const PackedFloat32Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return &self->ptr()[p_index]; return &self->ptr()[p_index];
} }
static double *gdextension_packed_float64_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { static double *gdextension_packed_float64_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
PackedFloat64Array *self = (PackedFloat64Array *)p_self; PackedFloat64Array *self = (PackedFloat64Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return &self->ptrw()[p_index]; return &self->ptrw()[p_index];
} }
static const double *gdextension_packed_float64_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) { static const double *gdextension_packed_float64_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
const PackedFloat64Array *self = (const PackedFloat64Array *)p_self; const PackedFloat64Array *self = (const PackedFloat64Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return &self->ptr()[p_index]; return &self->ptr()[p_index];
} }
static int32_t *gdextension_packed_int32_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { static int32_t *gdextension_packed_int32_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
PackedInt32Array *self = (PackedInt32Array *)p_self; PackedInt32Array *self = (PackedInt32Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return &self->ptrw()[p_index]; return &self->ptrw()[p_index];
} }
static const int32_t *gdextension_packed_int32_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) { static const int32_t *gdextension_packed_int32_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
const PackedInt32Array *self = (const PackedInt32Array *)p_self; const PackedInt32Array *self = (const PackedInt32Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return &self->ptr()[p_index]; return &self->ptr()[p_index];
} }
static int64_t *gdextension_packed_int64_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { static int64_t *gdextension_packed_int64_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
PackedInt64Array *self = (PackedInt64Array *)p_self; PackedInt64Array *self = (PackedInt64Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return &self->ptrw()[p_index]; return &self->ptrw()[p_index];
} }
static const int64_t *gdextension_packed_int64_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) { static const int64_t *gdextension_packed_int64_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
const PackedInt64Array *self = (const PackedInt64Array *)p_self; const PackedInt64Array *self = (const PackedInt64Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return &self->ptr()[p_index]; return &self->ptr()[p_index];
} }
static GDExtensionStringPtr gdextension_packed_string_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { static GDExtensionStringPtr gdextension_packed_string_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
PackedStringArray *self = (PackedStringArray *)p_self; PackedStringArray *self = (PackedStringArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return (GDExtensionStringPtr)&self->ptrw()[p_index]; return (GDExtensionStringPtr)&self->ptrw()[p_index];
} }
static GDExtensionStringPtr gdextension_packed_string_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) { static GDExtensionStringPtr gdextension_packed_string_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
const PackedStringArray *self = (const PackedStringArray *)p_self; const PackedStringArray *self = (const PackedStringArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return (GDExtensionStringPtr)&self->ptr()[p_index]; return (GDExtensionStringPtr)&self->ptr()[p_index];
} }
static GDExtensionTypePtr gdextension_packed_vector2_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { static GDExtensionTypePtr gdextension_packed_vector2_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
PackedVector2Array *self = (PackedVector2Array *)p_self; PackedVector2Array *self = (PackedVector2Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return (GDExtensionTypePtr)&self->ptrw()[p_index]; return (GDExtensionTypePtr)&self->ptrw()[p_index];
} }
static GDExtensionTypePtr gdextension_packed_vector2_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) { static GDExtensionTypePtr gdextension_packed_vector2_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
const PackedVector2Array *self = (const PackedVector2Array *)p_self; const PackedVector2Array *self = (const PackedVector2Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return (GDExtensionTypePtr)&self->ptr()[p_index]; return (GDExtensionTypePtr)&self->ptr()[p_index];
} }
static GDExtensionTypePtr gdextension_packed_vector3_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { static GDExtensionTypePtr gdextension_packed_vector3_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
PackedVector3Array *self = (PackedVector3Array *)p_self; PackedVector3Array *self = (PackedVector3Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return (GDExtensionTypePtr)&self->ptrw()[p_index]; return (GDExtensionTypePtr)&self->ptrw()[p_index];
} }
static GDExtensionTypePtr gdextension_packed_vector3_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) { static GDExtensionTypePtr gdextension_packed_vector3_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
const PackedVector3Array *self = (const PackedVector3Array *)p_self; const PackedVector3Array *self = (const PackedVector3Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return (GDExtensionTypePtr)&self->ptr()[p_index]; return (GDExtensionTypePtr)&self->ptr()[p_index];
} }
static GDExtensionVariantPtr gdextension_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { static GDExtensionVariantPtr gdextension_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
Array *self = (Array *)p_self; Array *self = (Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return (GDExtensionVariantPtr)&self->operator[](p_index); return (GDExtensionVariantPtr)&self->operator[](p_index);
} }
static GDExtensionVariantPtr gdextension_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) { static GDExtensionVariantPtr gdextension_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
const Array *self = (const Array *)p_self; const Array *self = (const Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); if (unlikely(p_index < 0 || p_index >= self->size())) {
return nullptr;
}
return (GDExtensionVariantPtr)&self->operator[](p_index); return (GDExtensionVariantPtr)&self->operator[](p_index);
} }