Skip to content

Commit 27697cf

Browse files
committed
Fix allocation of hash key
1 parent cef8afe commit 27697cf

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

src/tarantool.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ int get_spaceno_by_name(tarantool_connection *obj, zval *name) {
663663
}
664664

665665
if (tarantool_schema_add_spaces(obj->schema, resp.data, resp.data_len)) {
666-
tutils_hexdump_base(stderr, "\n", resp.data, resp.data_len);
667666
tarantool_throw_parsingexception("schema (space)");
668667
return FAILURE;
669668
}
@@ -722,8 +721,8 @@ int get_indexno_by_name(tarantool_connection *obj, int space_no,
722721
return FAILURE;
723722
}
724723

725-
if (tarantool_schema_add_indexes(obj->schema, resp.data, resp.data_len)) {
726-
tutils_hexdump_base(stderr, "\n", resp.data, resp.data_len);
724+
if (tarantool_schema_add_indexes(obj->schema, resp.data,
725+
resp.data_len) == -1) {
727726
tarantool_throw_parsingexception("schema (index)");
728727
return FAILURE;
729728
}
@@ -778,7 +777,6 @@ int get_fieldno_by_name(tarantool_connection *obj, uint32_t space_no,
778777
}
779778

780779
if (tarantool_schema_add_spaces(obj->schema, resp.data, resp.data_len)) {
781-
tutils_hexdump_base(stderr, "\n", resp.data, resp.data_len);
782780
tarantool_throw_parsingexception("schema (space)");
783781
return FAILURE;
784782
}
@@ -1207,7 +1205,8 @@ int __tarantool_authenticate(tarantool_connection *obj) {
12071205
if (tarantool_stream_read(obj, obj->value->c,
12081206
body_size) == FAILURE)
12091207
return FAILURE;
1210-
if (status == FAILURE) continue;
1208+
if (status == FAILURE)
1209+
continue;
12111210
struct tnt_response resp;
12121211
memset(&resp, 0, sizeof(struct tnt_response));
12131212
if (php_tp_response(&resp, obj->value->c, body_size) == -1) {
@@ -1220,29 +1219,22 @@ int __tarantool_authenticate(tarantool_connection *obj) {
12201219
resp.error_len);
12211220
status = FAILURE;
12221221
}
1223-
if (resp.sync == space_sync) {
1224-
if (tarantool_schema_add_spaces(obj->schema, resp.data,
1225-
resp.data_len) &&
1226-
status != FAILURE) {
1227-
tutils_hexdump_base(stderr, "\n", resp.data, resp.data_len);
1222+
if (status != FAILURE) {
1223+
if (resp.sync == space_sync && tarantool_schema_add_spaces(
1224+
obj->schema,
1225+
resp.data,
1226+
resp.data_len) == -1) {
12281227
tarantool_throw_parsingexception("schema (space)");
12291228
status = FAILURE;
1230-
}
1231-
} else if (resp.sync == index_sync) {
1232-
if (tarantool_schema_add_indexes(obj->schema, resp.data,
1233-
resp.data_len) &&
1234-
status != FAILURE) {
1235-
tutils_hexdump_base(stderr, "\n", resp.data, resp.data_len);
1229+
} else if (resp.sync == index_sync && tarantool_schema_add_indexes(
1230+
obj->schema,
1231+
resp.data,
1232+
resp.data_len) == -1) {
12361233
tarantool_throw_parsingexception("schema (index)");
12371234
status = FAILURE;
12381235
}
1239-
} else if (resp.sync == auth_sync && resp.error) {
1240-
tarantool_throw_clienterror(resp.code, resp.error,
1241-
resp.error_len);
1242-
status = FAILURE;
12431236
}
12441237
}
1245-
12461238
return status;
12471239
}
12481240

src/tarantool_schema.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ schema_index_free(struct mh_schema_index_t *schema) {
7878
do {
7979
struct schema_key key_number = {
8080
(void *)&(ivalue->index_number),
81-
sizeof(uint32_t)
81+
sizeof(uint32_t), 0
8282
};
8383
index_slot = mh_schema_index_find(schema, &key_number,
8484
NULL);
@@ -90,7 +90,7 @@ schema_index_free(struct mh_schema_index_t *schema) {
9090
do {
9191
struct schema_key key_string = {
9292
ivalue->index_name,
93-
ivalue->index_name_len
93+
ivalue->index_name_len, 0
9494
};
9595
index_slot = mh_schema_index_find(schema, &key_string,
9696
NULL);
@@ -170,7 +170,7 @@ schema_space_free(struct mh_schema_space_t *schema) {
170170
do {
171171
struct schema_key key_number = {
172172
(void *)&(svalue->space_number),
173-
sizeof(uint32_t)
173+
sizeof(uint32_t), 0
174174
};
175175
space_slot = mh_schema_space_find(schema, &key_number,
176176
NULL);
@@ -182,7 +182,7 @@ schema_space_free(struct mh_schema_space_t *schema) {
182182
do {
183183
struct schema_key key_string = {
184184
svalue->space_name,
185-
svalue->space_name_len
185+
svalue->space_name_len, 0
186186
};
187187
space_slot = mh_schema_space_find(schema, &key_string,
188188
NULL);
@@ -404,16 +404,18 @@ tarantool_schema_add_spaces(
404404
struct mh_schema_space_t *schema = schema_obj->space_hash;
405405
const char *tuple = data;
406406
if (mp_check(&tuple, tuple + size))
407-
return -1;
407+
goto error;
408408
tuple = data;
409409
if (mp_typeof(*tuple) != MP_ARRAY)
410-
return -1;
410+
goto error;
411411
uint32_t space_count = mp_decode_array(&tuple);
412412
while (space_count-- > 0) {
413413
if (schema_add_space(schema, &tuple))
414-
return -1;
414+
goto error;
415415
}
416416
return 0;
417+
error:
418+
return -1;
417419
}
418420

419421
static inline int schema_add_index(
@@ -449,8 +451,8 @@ static inline int schema_add_index(
449451
case 0:
450452
if (mp_typeof(*tuple) != MP_UINT)
451453
goto error;
452-
uint32_t space_number = mp_decode_uint(&tuple);
453-
space_key.id = (void *)&(space_number);
454+
space_key.number = mp_decode_uint(&tuple);
455+
space_key.id = (void *)&(space_key.number);
454456
space_key.id_len = sizeof(uint32_t);
455457
break;
456458
/* index ID */
@@ -520,16 +522,18 @@ tarantool_schema_add_indexes(
520522
struct mh_schema_space_t *schema = schema_obj->space_hash;
521523
const char *tuple = data;
522524
if (mp_check(&tuple, tuple + size))
523-
return -1;
525+
goto error;
524526
tuple = data;
525527
if (mp_typeof(*tuple) != MP_ARRAY)
526-
return -1;
528+
goto error;
527529
uint32_t space_count = mp_decode_array(&tuple);
528530
while (space_count-- > 0) {
529531
if (schema_add_index(schema, &tuple))
530-
return -1;
532+
goto error;
531533
}
532534
return 0;
535+
error:
536+
return -1;
533537
}
534538

535539
int32_t
@@ -540,7 +544,7 @@ tarantool_schema_get_sid_by_string(
540544
struct mh_schema_space_t *schema = schema_obj->space_hash;
541545
struct schema_key space_key = {
542546
space_name,
543-
space_name_len
547+
space_name_len, 0
544548
};
545549
mh_int_t space_slot = mh_schema_space_find(schema, &space_key, NULL);
546550
if (space_slot == mh_end(schema))
@@ -558,7 +562,7 @@ tarantool_schema_get_iid_by_string(
558562
struct mh_schema_space_t *schema = schema_obj->space_hash;
559563
struct schema_key space_key = {
560564
(void *)&sid,
561-
sizeof(uint32_t)
565+
sizeof(uint32_t), 0
562566
};
563567
mh_int_t space_slot = mh_schema_space_find(schema, &space_key, NULL);
564568
if (space_slot == mh_end(schema))
@@ -567,7 +571,7 @@ tarantool_schema_get_iid_by_string(
567571
space_slot);
568572
struct schema_key index_key = {
569573
index_name,
570-
index_name_len
574+
index_name_len, 0
571575
};
572576
mh_int_t index_slot = mh_schema_index_find(space->index_hash,
573577
&index_key, NULL);
@@ -586,7 +590,7 @@ tarantool_schema_get_fid_by_string(
586590
struct mh_schema_space_t *schema = schema_obj->space_hash;
587591
struct schema_key space_key = {
588592
(void *)&sid,
589-
sizeof(uint32_t)
593+
sizeof(uint32_t), 0
590594
};
591595
mh_int_t space_slot = mh_schema_space_find(schema, &space_key, NULL);
592596
if (space_slot == mh_end(schema))

src/tarantool_schema.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
struct schema_key {
55
const char *id;
66
uint32_t id_len;
7+
uint32_t number;
78
};
89

910
enum field_type {

0 commit comments

Comments
 (0)