Re: Patch 8.2.3871
John Marriott wrote: > >> On 23-Dec-2021 05:20, Bram Moolenaar wrote: > >>> Patch 8.2.3871 > >>> Problem:List.c contains code for dict and blob. > >>> Solution: Refactor to put code where it belongs. (Yegappan Lakshmanan, > >>> closes #9386) > >>> Files: src/blob.c, src/dict.c, src/list.c, src/proto/blob.pro, > >>> src/proto/dict.pro, src/proto/list.pro, > >>> src/proto/strings.pro, > >>> src/strings.c, src/structs.h, > >>> src/testdir/test_filter_map.vim, > >>> src/testdir/test_listdict.vim, src/testdir/test_sort.vim > >>> > >>> > > Is that because of the "actually longer" thing? > Yeah I think so. > > Any idea how to avoid the error? > > > > The attached patch changes dictitem_alloc() to use the same mechanism as > dictitem_copy() just below it. > > What do you think? If this avoids the warning then it's fine. Thanks for the patch. -- % cat /usr/include/real_life.h void life(void); /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\help me help AIDS victims -- http://ICCF-Holland.org/// -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/2021103038.E22421C0641%40moolenaar.net.
Re: Patch 8.2.3871
On 23-Dec-2021 06:19, Bram Moolenaar wrote: John Marriott wrote: On 23-Dec-2021 05:20, Bram Moolenaar wrote: Patch 8.2.3871 Problem:List.c contains code for dict and blob. Solution: Refactor to put code where it belongs. (Yegappan Lakshmanan, closes #9386) Files: src/blob.c, src/dict.c, src/list.c, src/proto/blob.pro, src/proto/dict.pro, src/proto/list.pro, src/proto/strings.pro, src/strings.c, src/structs.h, src/testdir/test_filter_map.vim, src/testdir/test_listdict.vim, src/testdir/test_sort.vim Is that because of the "actually longer" thing? Yeah I think so. Any idea how to avoid the error? The attached patch changes dictitem_alloc() to use the same mechanism as dictitem_copy() just below it. What do you think? Cheers John -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/f9082c33-d8c1-3ba8-91ac-3a32b80045e7%40internode.on.net. --- dict.c.orig 2021-12-23 05:28:28.586848100 +1100 +++ dict.c 2021-12-23 07:12:53.587225300 +1100 @@ -222,11 +222,12 @@ dictitem_alloc(char_u *key) { dictitem_T *di; +size_t len = STRLEN(key); -di = alloc(offsetof(dictitem_T, di_key) + STRLEN(key) + 1); +di = alloc(offsetof(dictitem_T, di_key) + len + 1); if (di != NULL) { - STRCPY(di->di_key, key); + mch_memmove(di->di_key, key, len + 1); di->di_flags = DI_FLAGS_ALLOC; di->di_tv.v_lock = 0; di->di_tv.v_type = VAR_UNKNOWN;
Re: Patch 8.2.3871
John Marriott wrote: > On 23-Dec-2021 05:20, Bram Moolenaar wrote: > > Patch 8.2.3871 > > Problem:List.c contains code for dict and blob. > > Solution: Refactor to put code where it belongs. (Yegappan Lakshmanan, > > closes #9386) > > Files: src/blob.c, src/dict.c, src/list.c, src/proto/blob.pro, > > src/proto/dict.pro, src/proto/list.pro, src/proto/strings.pro, > > src/strings.c, src/structs.h, src/testdir/test_filter_map.vim, > > src/testdir/test_listdict.vim, src/testdir/test_sort.vim > > > > > After this patch, mingw64 (gcc 11.2.0) spits out this warning: > > gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603 > -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO > -pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return > -fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD dict.c -o gobjnative/dict.o > In file included from dict.c:14: > In function 'dictitem_alloc', > inlined from 'dict_add_tv' at dict.c:491:12, > inlined from 'dict_filter_map' at dict.c:1370:7: > vim.h:1629:29: warning: 'strcpy' offset 0 from the object at '' > is out of the bounds of referenced subobject 'di_key' with type > 'char_u[1]' {aka 'unsigned char[1]'} at offset 0 [-Warray-bounds] > 1629 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s)) > | ^~~~ > vim.h:1629:29: note: in definition of macro 'STRCPY' > 1629 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s)) > | ^~ > In file included from vim.h:1878, > from dict.c:14: > dict.c: In function 'dict_filter_map': > structs.h:1538:17: note: subobject 'di_key' declared here > 1538 | char_u di_key[1]; // key (actually longer!) > | ^~ > Is that because of the "actually longer" thing? Any idea how to avoid the error? -- >From "know your smileys": <<<:-{Worf (Never smiles anyways, so he's a bad smiley) /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\help me help AIDS victims -- http://ICCF-Holland.org/// -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/20211222191935.349F41C0641%40moolenaar.net.
Re: Patch 8.2.3871
Hi, On Wed, Dec 22, 2021 at 10:46 AM John Marriott wrote: > > > On 23-Dec-2021 05:20, Bram Moolenaar wrote: > > Patch 8.2.3871 > > Problem:List.c contains code for dict and blob. > > Solution: Refactor to put code where it belongs. (Yegappan Lakshmanan, > > closes #9386) > > Files: src/blob.c, src/dict.c, src/list.c, src/proto/blob.pro, > > src/proto/dict.pro, src/proto/list.pro, src/proto/strings.pro, > > src/strings.c, src/structs.h, src/testdir/test_filter_map.vim, > > src/testdir/test_listdict.vim, src/testdir/test_sort.vim > > > > > After this patch, mingw64 (gcc 11.2.0) spits out this warning: > > gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603 > -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO > -pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return > -fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD dict.c -o gobjnative/dict.o > In file included from dict.c:14: > In function 'dictitem_alloc', > inlined from 'dict_add_tv' at dict.c:491:12, > inlined from 'dict_filter_map' at dict.c:1370:7: > vim.h:1629:29: warning: 'strcpy' offset 0 from the object at '' > is out of the bounds of referenced subobject 'di_key' with type > 'char_u[1]' {aka 'unsigned char[1]'} at offset 0 [-Warray-bounds] > 1629 | #define STRCPY(d, s)strcpy((char *)(d), (char *)(s)) >| ^~~~ > vim.h:1629:29: note: in definition of macro 'STRCPY' > 1629 | #define STRCPY(d, s)strcpy((char *)(d), (char *)(s)) >| ^~ > In file included from vim.h:1878, > from dict.c:14: > dict.c: In function 'dict_filter_map': > structs.h:1538:17: note: subobject 'di_key' declared here > 1538 | char_u di_key[1]; // key (actually longer!) >| ^~ > > This patch did not change the dictitem_T definition or modify the dict_add_tv() or the dictitem_alloc() functions. It looks like GCC is complaining about using the di_key buffer with size 1 (even though the size of the di_key array is greater than 1). Interestingly GCC is not complaining about the use of this function in other places. - Yegappan -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/CAAW7x7kWkMoPEX8Cm%2B0%2Bqcam9QrEOGdgDxPxFyU%3DNRs3N%2BGRhA%40mail.gmail.com.
Re: Patch 8.2.3871
On 23-Dec-2021 05:20, Bram Moolenaar wrote: Patch 8.2.3871 Problem:List.c contains code for dict and blob. Solution: Refactor to put code where it belongs. (Yegappan Lakshmanan, closes #9386) Files: src/blob.c, src/dict.c, src/list.c, src/proto/blob.pro, src/proto/dict.pro, src/proto/list.pro, src/proto/strings.pro, src/strings.c, src/structs.h, src/testdir/test_filter_map.vim, src/testdir/test_listdict.vim, src/testdir/test_sort.vim After this patch, mingw64 (gcc 11.2.0) spits out this warning: gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603 -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO -pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return -fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD dict.c -o gobjnative/dict.o In file included from dict.c:14: In function 'dictitem_alloc', inlined from 'dict_add_tv' at dict.c:491:12, inlined from 'dict_filter_map' at dict.c:1370:7: vim.h:1629:29: warning: 'strcpy' offset 0 from the object at '' is out of the bounds of referenced subobject 'di_key' with type 'char_u[1]' {aka 'unsigned char[1]'} at offset 0 [-Warray-bounds] 1629 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s)) | ^~~~ vim.h:1629:29: note: in definition of macro 'STRCPY' 1629 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s)) | ^~ In file included from vim.h:1878, from dict.c:14: dict.c: In function 'dict_filter_map': structs.h:1538:17: note: subobject 'di_key' declared here 1538 | char_u di_key[1]; // key (actually longer!) | ^~ Cheers John -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/c69a6da9-875d-32ca-11d8-07723c06d4ff%40internode.on.net.
Patch 8.2.3871
Patch 8.2.3871 Problem:List.c contains code for dict and blob. Solution: Refactor to put code where it belongs. (Yegappan Lakshmanan, closes #9386) Files: src/blob.c, src/dict.c, src/list.c, src/proto/blob.pro, src/proto/dict.pro, src/proto/list.pro, src/proto/strings.pro, src/strings.c, src/structs.h, src/testdir/test_filter_map.vim, src/testdir/test_listdict.vim, src/testdir/test_sort.vim *** ../vim-8.2.3870/src/blob.c 2021-12-19 19:19:27.818424761 + --- src/blob.c 2021-12-22 18:04:56.843931664 + *** *** 410,487 } /* ! * "remove({blob})" function */ void blob_remove(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg) { blob_T*b = argvars[0].vval.v_blob; int error = FALSE; long idx; long end; if (b != NULL && value_check_lock(b->bv_lock, arg_errmsg, TRUE)) return; idx = (long)tv_get_number_chk([1], ); ! if (!error) { ! int len = blob_len(b); ! char_u *p; ! if (idx < 0) ! // count from the end ! idx = len + idx; ! if (idx < 0 || idx >= len) ! { ! semsg(_(e_blobidx), idx); return; } ! if (argvars[2].v_type == VAR_UNKNOWN) { ! // Remove one item, return its value. ! p = (char_u *)b->bv_ga.ga_data; ! rettv->vval.v_number = (varnumber_T) *(p + idx); ! mch_memmove(p + idx, p + idx + 1, (size_t)len - idx - 1); --b->bv_ga.ga_len; } ! else { ! blob_T *blob; ! // Remove range of items, return blob with values. ! end = (long)tv_get_number_chk([2], ); ! if (error) ! return; ! if (end < 0) ! // count from the end ! end = len + end; ! if (end >= len || idx > end) ! { ! semsg(_(e_blobidx), end); ! return; ! } ! blob = blob_alloc(); ! if (blob == NULL) ! return; ! blob->bv_ga.ga_len = end - idx + 1; ! if (ga_grow(>bv_ga, end - idx + 1) == FAIL) ! { ! vim_free(blob); ! return; ! } ! p = (char_u *)b->bv_ga.ga_data; ! mch_memmove((char_u *)blob->bv_ga.ga_data, p + idx, ! (size_t)(end - idx + 1)); ! ++blob->bv_refcount; ! rettv->v_type = VAR_BLOB; ! rettv->vval.v_blob = blob; ! ! if (len - end - 1 > 0) ! mch_memmove(p + idx, p + end + 1, (size_t)(len - end - 1)); ! b->bv_ga.ga_len -= end - idx + 1; } } } /* --- 410,715 } /* ! * "add(blob, item)" function ! */ ! void ! blob_add(typval_T *argvars, typval_T *rettv) ! { ! blob_T*b = argvars[0].vval.v_blob; ! int error = FALSE; ! varnumber_T n; ! ! if (b == NULL) ! { ! if (in_vim9script()) ! emsg(_(e_cannot_add_to_null_blob)); ! return; ! } ! ! if (value_check_lock(b->bv_lock, (char_u *)N_("add() argument"), TRUE)) ! return; ! ! n = tv_get_number_chk([1], ); ! if (error) ! return; ! ! ga_append(>bv_ga, (int)n); ! copy_tv([0], rettv); ! } ! ! /* ! * "remove({blob}, {idx} [, {end}])" function */ void blob_remove(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg) { blob_T*b = argvars[0].vval.v_blob; + blob_T*newblob; int error = FALSE; long idx; long end; + int len; + char_u*p; if (b != NULL && value_check_lock(b->bv_lock, arg_errmsg, TRUE)) return; idx = (long)tv_get_number_chk([1], ); ! if (error) ! return; ! ! len = blob_len(b); ! ! if (idx < 0) ! // count from the end ! idx = len + idx; ! if (idx < 0 || idx >= len) ! { ! semsg(_(e_blobidx), idx); ! return; ! } ! if (argvars[2].v_type == VAR_UNKNOWN) { ! // Remove one item, return its value. ! p = (char_u *)b->bv_ga.ga_data; ! rettv->vval.v_number = (varnumber_T) *(p + idx); ! mch_memmove(p + idx, p + idx + 1, (size_t)len - idx - 1); ! --b->bv_ga.ga_len; ! return; ! } ! // Remove range of items, return blob with values. ! end = (long)tv_get_number_chk([2], ); ! if (error) ! return; ! if (end < 0) ! // count from the end ! end = len + end; ! if (end >= len || idx > end) ! { ! semsg(_(e_blobidx), end); ! return; ! } ! newblob = blob_alloc(); ! if (newblob == NULL) ! return; ! newblo