-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-39138: Fix ER_OUTOFMEMORY to use %zu (10.6) #4850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 10.6
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,24 @@ int st_append_json(String *s, | |
| return 0; | ||
| } | ||
|
|
||
| str_len= json_unescape(json_cs, js, js + js_len, s->charset(), | ||
| (uchar *) s->end(), (uchar *) s->end() + str_len); | ||
| if (str_len > 0) | ||
| s->length(s->length() + str_len); | ||
|
|
||
| if (str_len >= 0) | ||
| return 0; | ||
|
|
||
| if (current_thd) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's always current_thd! Please turn this into an assert? |
||
| { | ||
| if (str_len == JSON_ERROR_OUT_OF_SPACE) | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)js_len); | ||
| else if (str_len == JSON_ERROR_ILLEGAL_SYMBOL) | ||
| push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, | ||
| ER_JSON_BAD_CHR, ER_THD(current_thd, ER_JSON_BAD_CHR), | ||
| 0, "st_append_json", 0); | ||
| } | ||
|
|
||
| return str_len; | ||
| } | ||
|
|
||
|
|
@@ -805,6 +823,15 @@ String *Item_func_json_unquote::val_str(String *str) | |
|
|
||
| error: | ||
| report_json_error(js, &je, 0); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. report_json_error already reports an error. Why do you need to duplicate this? I'd rather extend report_json_error() to include the length and extend it to report out of memory. |
||
| if (current_thd) | ||
| { | ||
| if (c_len == JSON_ERROR_OUT_OF_SPACE) | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)je.value_len); | ||
| else if (c_len == JSON_ERROR_ILLEGAL_SYMBOL) | ||
| push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, | ||
| ER_JSON_BAD_CHR, ER_THD(current_thd, ER_JSON_BAD_CHR), | ||
| 0, "unquote", 0); | ||
| } | ||
| return js; | ||
| } | ||
|
|
||
|
|
@@ -2108,6 +2135,38 @@ String *Item_func_json_array_insert::val_str(String *str) | |
| (n_item == 0 && str->append(" ", 1)) || | ||
| append_simple(str, item_pos, js->end() - item_pos)) | ||
| goto return_null; /* Out of memory. */ | ||
| my_ptrdiff_t size= item_pos - js->ptr(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either something is wrong with the diff or you've inadvertently left the original you're trying to change too. |
||
| if (append_simple(str, js->ptr(), size)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t) size); | ||
| goto return_null; /* Out of memory. */ | ||
| } | ||
| if (n_item > 0 && str->append(" ", 1)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)1); | ||
| goto return_null; /* Out of memory. */ | ||
| } | ||
| if (append_json_value(str, args[n_arg+1], &tmp_val)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)tmp_val.length()); | ||
| goto return_null; /* Out of memory. */ | ||
| } | ||
| if (str->append(",", 1)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)1); | ||
| goto return_null; /* Out of memory. */ | ||
| } | ||
| if (n_item == 0 && str->append(" ", 1)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)1); | ||
| goto return_null; /* Out of memory. */ | ||
| } | ||
| size= js->end() - item_pos; | ||
| if (append_simple(str, item_pos, size)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t) size); | ||
| goto return_null; /* Out of memory. */ | ||
| } | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -2119,6 +2178,28 @@ String *Item_func_json_array_insert::val_str(String *str) | |
| append_json_value(str, args[n_arg+1], &tmp_val) || | ||
| append_simple(str, item_pos, js->end() - item_pos)) | ||
| goto return_null; /* Out of memory. */ | ||
| size= item_pos - js->ptr(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto here: see the other comment. |
||
| if (append_simple(str, js->ptr(), size)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t) size); | ||
| goto return_null; /* Out of memory. */ | ||
| } | ||
| if (n_item > 0 && str->append(", ", 2)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)2); | ||
| goto return_null; /* Out of memory. */ | ||
| } | ||
| if (append_json_value(str, args[n_arg+1], &tmp_val)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)tmp_val.length()); | ||
| goto return_null; /* Out of memory. */ | ||
| } | ||
| size= js->end() - item_pos; | ||
| if (append_simple(str, item_pos, size)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t) size); | ||
| goto return_null; /* Out of memory. */ | ||
| } | ||
| } | ||
|
|
||
| { | ||
|
|
@@ -3688,6 +3769,19 @@ int Item_func_json_search::compare_json_value_wild(json_engine_t *je, | |
| (uchar *) (esc_value.ptr() + | ||
| esc_value.alloced_length())); | ||
| if (esc_len <= 0) | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd consider using (the extended) report_json_error() here too. |
||
| if (current_thd) | ||
| { | ||
| if (esc_len == JSON_ERROR_OUT_OF_SPACE) | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)je->value_len); | ||
| else if (esc_len == JSON_ERROR_ILLEGAL_SYMBOL) | ||
| { | ||
| push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, | ||
| ER_JSON_BAD_CHR, ER_THD(current_thd, ER_JSON_BAD_CHR), | ||
| 0, "comparison", | ||
| (int)(je->s.c_str - je->value)); | ||
| } | ||
| } | ||
| return 0; | ||
|
|
||
| return collation.collation->wildcmp( | ||
|
|
@@ -3933,10 +4027,28 @@ int Arg_comparator::compare_json_str_basic(Item *j, Item *s) | |
| { | ||
| if (value2.realloc_with_extra_if_needed(je.value_len) || | ||
| (c_len= json_unescape(js->charset(), je.value, | ||
| if (value2.realloc_with_extra_if_needed(je.value_len)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you've again left the original call. |
||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)je.value_len); | ||
| goto error; | ||
| } | ||
| if ((c_len= json_unescape(js->charset(), je.value, | ||
| je.value + je.value_len, | ||
| &my_charset_utf8mb3_general_ci, | ||
| (uchar *) value2.ptr(), | ||
| (uchar *) (value2.ptr() + je.value_len))) < 0) | ||
| { | ||
| if (current_thd) | ||
| { | ||
| if (c_len == JSON_ERROR_OUT_OF_SPACE) | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)je.value_len); | ||
| else if (c_len == JSON_ERROR_ILLEGAL_SYMBOL) | ||
| { | ||
| push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, | ||
| ER_JSON_BAD_CHR, ER_THD(current_thd, ER_JSON_BAD_CHR), | ||
| 0, "comparison", (int)((const char *) je.s.c_str - js->ptr())); | ||
| } | ||
| } | ||
| goto error; | ||
|
|
||
| value2.length(c_len); | ||
|
|
@@ -3982,11 +4094,31 @@ int Arg_comparator::compare_e_json_str_basic(Item *j, Item *s) | |
| { | ||
| if (value1.realloc_with_extra_if_needed(value_len) || | ||
| (c_len= json_unescape(value1.charset(), (uchar *) value, | ||
| if (value1.realloc_with_extra_if_needed(value_len)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)value_len); | ||
| return 1; | ||
| } | ||
| if ((c_len= json_unescape(value1.charset(), (uchar *) value, | ||
| (uchar *) value+value_len, | ||
| &my_charset_utf8mb3_general_ci, | ||
| (uchar *) value1.ptr(), | ||
| (uchar *) (value1.ptr() + value_len))) < 0) | ||
| return 1; | ||
| { | ||
| if (current_thd) | ||
| { | ||
| if (c_len == JSON_ERROR_OUT_OF_SPACE) | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)value_len); | ||
| else if (c_len == JSON_ERROR_ILLEGAL_SYMBOL) | ||
| { | ||
| push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, | ||
| ER_JSON_BAD_CHR, ER_THD(current_thd, ER_JSON_BAD_CHR), | ||
| 0, "equality comparison", 0); | ||
| } | ||
| } | ||
| return 1; | ||
| } | ||
| value1.length(c_len); | ||
| res1= &value1; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5392,7 +5392,7 @@ String *Item_func_wsrep_last_written_gtid::val_str_ascii(String *str) | |
| { | ||
| if (gtid_str.alloc(WSREP_MAX_WSREP_SERVER_GTID_STR_LEN+1)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), WSREP_MAX_WSREP_SERVER_GTID_STR_LEN); | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)WSREP_MAX_WSREP_SERVER_GTID_STR_LEN); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? revert the whole file please. |
||
| null_value= TRUE; | ||
| return 0; | ||
| } | ||
|
|
@@ -5417,7 +5417,7 @@ String *Item_func_wsrep_last_seen_gtid::val_str_ascii(String *str) | |
| { | ||
| if (gtid_str.alloc(WSREP_MAX_WSREP_SERVER_GTID_STR_LEN+1)) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), WSREP_MAX_WSREP_SERVER_GTID_STR_LEN); | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)WSREP_MAX_WSREP_SERVER_GTID_STR_LEN); | ||
| null_value= TRUE; | ||
| return 0; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -578,7 +578,7 @@ bool sysvartrack_global_update(THD *thd, char *str, size_t len) | |
| Session_sysvars_tracker::vars_list dummy; | ||
| DBUG_EXECUTE_IF("dbug_session_tracker_parse_error", | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), 1); | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (size_t)1); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert the whole file please |
||
| return true; | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1424,7 +1424,7 @@ resolve_engine_list(THD *thd, const char *str_arg, size_t str_arg_len, | |
| res= (plugin_ref *)my_malloc(PSI_INSTRUMENT_ME, (count+1)*sizeof(*res), MYF(MY_ZEROFILL|MY_WME)); | ||
| if (!res) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (int)((count+1)*sizeof(*res))); | ||
| my_error(ER_OUTOFMEMORY, MYF(0), ((count+1)*sizeof(*res))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert the whole file please. |
||
| goto err; | ||
| } | ||
|
|
||
|
|
@@ -1475,7 +1475,7 @@ copy_engine_list(plugin_ref *list) | |
| p= (plugin_ref *)my_malloc(PSI_INSTRUMENT_ME, (count+1)*sizeof(*p), MYF(0)); | ||
| if (!p) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (int)((count+1)*sizeof(*p))); | ||
| my_error(ER_OUTOFMEMORY, MYF(0), ((count+1)*sizeof(*p))); | ||
| return NULL; | ||
| } | ||
| for (i= 0; i < count; ++i) | ||
|
|
@@ -1500,7 +1500,7 @@ temp_copy_engine_list(THD *thd, plugin_ref *list) | |
| p= (plugin_ref *)thd->alloc((count+1)*sizeof(*p)); | ||
| if (!p) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(0), (int)((count+1)*sizeof(*p))); | ||
| my_error(ER_OUTOFMEMORY, MYF(0), ((count+1)*sizeof(*p))); | ||
| return NULL; | ||
| } | ||
| for (i= 0; i < count; ++i) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not change submodules! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to do json_unescape twice!