Skip to content

Commit 8402684

Browse files
committed
patch 7.4.2062
Problem: Using dummy variable to compute struct member offset. Solution: Use offsetof().
1 parent e87e6dd commit 8402684

5 files changed

Lines changed: 17 additions & 14 deletions

File tree

src/globals.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,18 +1649,6 @@ EXTERN int did_add_timer INIT(= FALSE);
16491649
#ifdef FEAT_EVAL
16501650
EXTERN time_T time_for_testing INIT(= 0);
16511651

1652-
/*
1653-
* In a hashtab item "hi_key" points to "di_key" in a dictitem.
1654-
* This avoids adding a pointer to the hashtab item.
1655-
* DI2HIKEY() converts a dictitem pointer to a hashitem key pointer.
1656-
* HIKEY2DI() converts a hashitem key pointer to a dictitem pointer.
1657-
* HI2DI() converts a hashitem pointer to a dictitem pointer.
1658-
*/
1659-
EXTERN dictitem_T dumdi;
1660-
# define DI2HIKEY(di) ((di)->di_key)
1661-
# define HIKEY2DI(p) ((dictitem_T *)(p - (dumdi.di_key - (char_u *)&dumdi)))
1662-
# define HI2DI(hi) HIKEY2DI((hi)->hi_key)
1663-
16641652
/* Abort conversion to string after a recursion error. */
16651653
EXTERN int did_echo_string_emsg INIT(= FALSE);
16661654
#endif

src/macros.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,14 @@
353353
# endif
354354
# endif
355355
#endif
356+
357+
/*
358+
* In a hashtab item "hi_key" points to "di_key" in a dictitem.
359+
* This avoids adding a pointer to the hashtab item.
360+
* DI2HIKEY() converts a dictitem pointer to a hashitem key pointer.
361+
* HIKEY2DI() converts a hashitem key pointer to a dictitem pointer.
362+
* HI2DI() converts a hashitem pointer to a dictitem pointer.
363+
*/
364+
# define DI2HIKEY(di) ((di)->di_key)
365+
# define HIKEY2DI(p) ((dictitem_T *)(p - offsetof(dictitem_T, di_key)))
366+
# define HI2DI(hi) HIKEY2DI((hi)->hi_key)

src/spell.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,7 @@ typedef struct wordcount_S
600600
char_u wc_word[1]; /* word, actually longer */
601601
} wordcount_T;
602602

603-
static wordcount_T dumwc;
604-
#define WC_KEY_OFF (unsigned)(dumwc.wc_word - (char_u *)&dumwc)
603+
#define WC_KEY_OFF offsetof(wordcount_T, wc_word)
605604
#define HI2WC(hi) ((wordcount_T *)((hi)->hi_key - WC_KEY_OFF))
606605
#define MAXWORDCOUNT 0xffff
607606

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ static char *(features[]) =
758758

759759
static int included_patches[] =
760760
{ /* Add new patch number below this line */
761+
/**/
762+
2062,
761763
/**/
762764
2061,
763765
/**/

src/vim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ typedef unsigned long u8char_T; /* long should be 32 bits or more */
505505
#endif
506506
#include <stdarg.h>
507507

508+
/* for offsetof() */
509+
#include <stddef.h>
510+
508511
#if defined(HAVE_SYS_SELECT_H) && \
509512
(!defined(HAVE_SYS_TIME_H) || defined(SYS_SELECT_WITH_SYS_TIME))
510513
# include <sys/select.h>

0 commit comments

Comments
 (0)