find: add zeroing of G.xxx; ftpd - remove extraneous zeroing of G.xxx

Brought "G trick" to the same shape in a few more places.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-09-30 02:39:57 +02:00
parent c34c033c42
commit 1b34d4f0b1
5 changed files with 17 additions and 14 deletions

View File

@ -36,8 +36,10 @@ struct globals {
off_t out_full, out_part, in_full, in_part; off_t out_full, out_part, in_full, in_part;
}; };
#define G (*(struct globals*)&bb_common_bufsiz1) #define G (*(struct globals*)&bb_common_bufsiz1)
/* We have to zero it out because of NOEXEC */ #define INIT_G() do { \
#define INIT_G() memset(&G, 0, sizeof(G)) /* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
} while (0)
static void dd_output_status(int UNUSED_PARAM cur_signal) static void dd_output_status(int UNUSED_PARAM cur_signal)

View File

@ -264,15 +264,15 @@ struct globals {
}; };
#define G (*(struct globals*)&bb_common_bufsiz1) #define G (*(struct globals*)&bb_common_bufsiz1)
#if ENABLE_FEATURE_LS_COLOR #if ENABLE_FEATURE_LS_COLOR
#define show_color (G.show_color ) # define show_color (G.show_color )
#else #else
enum { show_color = 0 }; enum { show_color = 0 };
#endif #endif
#define exit_code (G.exit_code ) #define exit_code (G.exit_code )
#define all_fmt (G.all_fmt ) #define all_fmt (G.all_fmt )
#if ENABLE_FEATURE_AUTOWIDTH #if ENABLE_FEATURE_AUTOWIDTH
#define tabstops (G.tabstops ) # define tabstops (G.tabstops )
#define terminal_width (G.terminal_width) # define terminal_width (G.terminal_width)
#else #else
enum { enum {
tabstops = COLUMN_GAP, tabstops = COLUMN_GAP,
@ -280,8 +280,8 @@ enum {
}; };
#endif #endif
#define current_time_t (G.current_time_t) #define current_time_t (G.current_time_t)
/* memset: we have to zero it out because of NOEXEC */
#define INIT_G() do { \ #define INIT_G() do { \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \ memset(&G, 0, sizeof(G)); \
IF_FEATURE_AUTOWIDTH(tabstops = COLUMN_GAP;) \ IF_FEATURE_AUTOWIDTH(tabstops = COLUMN_GAP;) \
IF_FEATURE_AUTOWIDTH(terminal_width = TERMINAL_WIDTH;) \ IF_FEATURE_AUTOWIDTH(terminal_width = TERMINAL_WIDTH;) \

View File

@ -109,6 +109,8 @@ struct globals {
struct G_sizecheck { \ struct G_sizecheck { \
char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \ char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \
}; \ }; \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, offsetof(struct globals, need_print)); \
G.need_print = 1; \ G.need_print = 1; \
G.recurse_flags = ACTION_RECURSE; \ G.recurse_flags = ACTION_RECURSE; \
} while (0) } while (0)

View File

@ -662,7 +662,7 @@ popen_ls(const char *opt)
execv(bb_busybox_exec_path + 1, (char**) argv); execv(bb_busybox_exec_path + 1, (char**) argv);
_exit(127); _exit(127);
#else #else
memset(&G, 0, sizeof(G)); /* memset(&G, 0, sizeof(G)); - ls_main does it */
exit(ls_main(ARRAY_SIZE(argv) - 1, (char**) argv)); exit(ls_main(ARRAY_SIZE(argv) - 1, (char**) argv));
#endif #endif
} }
@ -1114,7 +1114,7 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
/* --group-directories-first would be nice, but ls don't do that yet */ /* --group-directories-first would be nice, but ls don't do that yet */
xchdir(argv[2]); xchdir(argv[2]);
argv[2] = (char*)"--"; argv[2] = (char*)"--";
memset(&G, 0, sizeof(G)); /* memset(&G, 0, sizeof(G)); - ls_main does it */
return ls_main(argc, argv); return ls_main(argc, argv);
} }
#endif #endif

View File

@ -77,11 +77,10 @@ struct globals {
struct termios termios_raw; struct termios termios_raw;
}; };
#define G (*(struct globals*)&bb_common_bufsiz1) #define G (*(struct globals*)&bb_common_bufsiz1)
void BUG_telnet_globals_too_big(void);
#define INIT_G() do { \ #define INIT_G() do { \
if (sizeof(G) > COMMON_BUFSIZE) \ struct G_sizecheck { \
BUG_telnet_globals_too_big(); \ char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \
/* memset(&G, 0, sizeof G); - already is */ \ }; \
} while (0) } while (0)
/* Function prototypes */ /* Function prototypes */