← Commit list

8f4dc3b40

Denys Vlasenko
Denys Vlasenko
2026-08-31
SUCCESS Duration: 150s

Subject

platform.h: UNINITIALIZED_VAR() macro for suppressing gcc warnings

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

include/platform.h+15 -0
@@ -151,6 +151,21 @@
# endif
#endif
+/* Somewhere after gcc-9, it stopped recognizing "int var = var;" initializer
+ * as the "this variable is intentionally not initialized, don't warn" idiom.
+ */
+#if !__GNUC_PREREQ(10,0)
+# define UNINITIALIZED_VAR(var,zero) var = var
+#else
+# define UNINITIALIZED_VAR(var,zero) var = zero
+/* NB: in case newer gcc is able to see that the variable
+ * is never used before initialization on all possible code paths,
+ * you can use int UNINITIALIZED_VAR(var,var);
+ * instead of int UNINITIALIZED_VAR(var,0);
+ * and avoid having extra zeroing instruction.
+ */
+#endif
+
/* ---- Endian Detection ------------------------------------ */
miscutils/less.c+6 -5
@@ -469,7 +469,8 @@ static int at_end(void)
*/
static void read_lines(void)
{
- int ndelay_set, eagain, fdflags;
+ int ndelay_set, eagain;
+ int UNINITIALIZED_VAR(fdflags, fdflags);
char *current_line, *p;
int w = width;
char last_terminated = terminated;
@@ -501,16 +502,16 @@ static void read_lines(void)
// Consider these cases:
// "less FILE": can set O_NONBLOCK on open.
// "true | less": can't.
- // " { less; cat; } <FILE": can't. And must not confuse cat.
+ // "{ less; cat; } <FILE": can't. And must not confuse cat.
ndelay_set = -1; // "don't know whether stdin is nonblocking"
eagain = 0;
- while (1) { /* read lines until we reach cur_fline or wanted_match */
+ while (1) { // read lines until we reach cur_fline or wanted_match
*p = '\0';
terminated = 0;
- while (1) { /* read chars until we have a line */
+ while (1) { // read chars until we have a line
char c;
- /* if no unprocessed chars left, eat more */
+ // if no unprocessed chars left, eat more
if (readpos >= read_size) {
// Read stdin, temporarily make it nonblocking (if it's not already)
if (ndelay_set < 0) {
networking/tftp.c+1 -1
@@ -883,7 +883,7 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv)
len_and_sockaddr *our_lsa;
len_and_sockaddr *peer_lsa;
char *mode, *user_opt;
- char *local_file = local_file;
+ char *UNINITIALIZED_VAR(local_file, NULL);
const char *error_msg;
int opt, result, opcode;
IF_FEATURE_TFTP_BLOCKSIZE(int blksize = TFTP_BLKSIZE_DEFAULT;)
shell/hush.c+7 -7
@@ -7183,9 +7183,9 @@ static NOINLINE int expand_one_var(o_string *output, int n, char *arg, char **pp
char *p;
char *var;
char exp_op;
- char exp_save = exp_save; /* for compiler */
+ char UNINITIALIZED_VAR(exp_savech, exp_savech); /* for compiler */
char *exp_saveptr; /* points to expansion operator */
- char *exp_word = exp_word; /* for compiler */
+ char *UNINITIALIZED_VAR(exp_word, NULL); /* for compiler */
char arg0;
val = NULL;
@@ -7217,7 +7217,7 @@ static NOINLINE int expand_one_var(o_string *output, int n, char *arg, char **pp
/* ${?}, ${var}, ${var:0}, ${var[:]%0} etc */
exp_saveptr = var+1 + strcspn(var+1, VAR_ENCODED_SUBST_OPS);
}
- exp_op = exp_save = *exp_saveptr;
+ exp_op = exp_savech = *exp_saveptr;
if (exp_op) {
exp_word = exp_saveptr + 1;
if (exp_op == ':') {
@@ -7514,11 +7514,11 @@ static NOINLINE int expand_one_var(o_string *output, int n, char *arg, char **pp
* $ x=; f "${x:-'x y' z}"
* |'x y' z|
*/
- int use_word = (!val || ((exp_save == ':') && !val[0]));
+ int use_word = (!val || ((exp_savech == ':') && !val[0]));
if (exp_op == '+')
use_word = !use_word;
debug_printf_expand("expand: op:%c (null:%s) test:%i\n", exp_op,
- (exp_save == ':') ? "true" : "false", use_word);
+ (exp_savech == ':') ? "true" : "false", use_word);
if (use_word) {
if (exp_op == '+' || exp_op == '-') {
/* ${var+word} - use alternative value */
@@ -7545,7 +7545,7 @@ static NOINLINE int expand_one_var(o_string *output, int n, char *arg, char **pp
? exp_word
: "parameter null or not set"
/* ash has more specific messages, a-la: */
- /*: (exp_save == ':' ? "parameter null or not set" : "parameter not set")*/
+ /*: (exp_savech == ':' ? "parameter null or not set" : "parameter not set")*/
);
//TODO: how interactive bash aborts expansion mid-command?
//It aborts the entire line, returns to prompt:
@@ -7571,7 +7571,7 @@ static NOINLINE int expand_one_var(o_string *output, int n, char *arg, char **pp
}
} /* one of "-=+?" */
- *exp_saveptr = exp_save;
+ *exp_saveptr = exp_savech;
} /* if (exp_op) */
arg[0] = arg0;