diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-06-16 18:47:36 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2023-06-16 22:32:52 +0900 |
commit | 1ff20944107a20009445b1caac19a9b3728a3729 (patch) | |
tree | d07d9e8ad72560dc9c9cf3a83c86699491e0e702 /parser_st.c | |
parent | 60cf48ca4f09270bd87063d645018bca593c04d1 (diff) |
Copy `nonempty_memcpy` without ruby implementation
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7948
Diffstat (limited to 'parser_st.c')
-rw-r--r-- | parser_st.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/parser_st.c b/parser_st.c index 16ae6489a9..9f600c5d1f 100644 --- a/parser_st.c +++ b/parser_st.c @@ -115,7 +115,19 @@ #undef RUBY #undef MEMCPY -#define MEMCPY(tab,p1,p2,type,n) (tab->functions->nonempty_memcpy((p1), (p2), sizeof(type), (n))) +#define MEMCPY(p1,p2,type,n) nonempty_memcpy((p1), (p2), (sizeof(type) * (n))) +/* The multiplication should not overflow since this macro is used + * only with the already allocated size. */ +static inline void * +nonempty_memcpy(void *dest, const void *src, size_t n) +{ + if (n) { + return memcpy(dest, src, n); + } + else { + return dest; + } +} #include <stdio.h> #ifdef HAVE_STDLIB_H @@ -1313,7 +1325,6 @@ st_copy(st_table *old_tab) st_table *new_tab; new_tab = (st_table *) malloc(sizeof(st_table)); - new_tab->functions = old_tab->functions; #ifndef RUBY if (new_tab == NULL) return NULL; @@ -1338,10 +1349,10 @@ st_copy(st_table *old_tab) return NULL; } #endif - MEMCPY(new_tab, new_tab->entries, old_tab->entries, st_table_entry, + MEMCPY(new_tab->entries, old_tab->entries, st_table_entry, get_allocated_entries(old_tab)); if (old_tab->bins != NULL) - MEMCPY(new_tab, new_tab->bins, old_tab->bins, char, bins_size(old_tab)); + MEMCPY(new_tab->bins, old_tab->bins, char, bins_size(old_tab)); return new_tab; } |