From: Kern Sibbald Date: Mon, 19 Aug 2002 07:52:19 +0000 (+0000) Subject: Fix uninitialized variables X-Git-Tag: Release-1.25~41 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fa80a31b3fa72237958189e3797fddddd43f1fe0;p=bacula%2Fbacula Fix uninitialized variables git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@102 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/autoconf/configure.in b/bacula/autoconf/configure.in index 00d71c2bfe..77dab536cf 100644 --- a/bacula/autoconf/configure.in +++ b/bacula/autoconf/configure.in @@ -646,7 +646,7 @@ dnl# Supply default CFLAGS, if not specified by `CFLAGS=flags ./configure' dnl# if test -z "$CFLAGS"; then if test -z "$CCOPTS"; then - CCOPTS='-O' + CCOPTS='-g -O2' dnl> if test "x$GCC" = xyes; then dnl> if test x$system = xLinux; then dnl> CCOPTS="$CCOPTS "'-O2 -fno-strength-reduce' diff --git a/bacula/configure b/bacula/configure index 3728d59fd0..eafb9befd7 100755 --- a/bacula/configure +++ b/bacula/configure @@ -4028,7 +4028,7 @@ EOF if test -z "$CFLAGS"; then if test -z "$CCOPTS"; then - CCOPTS='-O' + CCOPTS='-g -O2' fi CFLAGS="$CCOPTS" fi diff --git a/bacula/kernstodo b/bacula/kernstodo index 0ecff1b5bc..24c3fd6a07 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -28,6 +28,8 @@ From Chuck: --sd.conf password does not match dir.conf storage password ======= +- Add new code to scheduler.c and run_conf.c +- Problem with len at 362 in tree.c - Volume Bytes shows bytes on last volume written in Job summary. - Fix catalog filename truncation in sql_get and sql_create. Use only a single filename split routine. diff --git a/bacula/src/console/console_conf.c b/bacula/src/console/console_conf.c index f0d30810f1..f8a79503c0 100644 --- a/bacula/src/console/console_conf.c +++ b/bacula/src/console/console_conf.c @@ -182,7 +182,7 @@ void save_resource(int type, struct res_items *items, int pass) { URES *res; int rindex = type - r_first; - int i, size; + int i, size; int error = 0; /* @@ -239,6 +239,7 @@ void save_resource(int type, struct res_items *items, int pass) default: printf("Unknown resource type %d\n", type); error = 1; + size = 1; break; } /* Common */ diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index d479797d9f..dd00ff9c18 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -892,6 +892,7 @@ void save_resource(int type, struct res_items *items, int pass) default: printf("Unknown resource type %d\n", type); error = 1; + size = 1; break; } /* Common */ diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index fb5f8a953e..d018ac3dbe 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -183,7 +183,7 @@ int send_exclude_list(JCR *jcr) int get_attributes_and_put_in_catalog(JCR *jcr) { BSOCK *fd; - int n; + int n = 0; ATTR_DBR ar; fd = jcr->file_bsock; diff --git a/bacula/src/dird/run_conf.c b/bacula/src/dird/run_conf.c index b9e307bad3..3efb8f24b6 100644 --- a/bacula/src/dird/run_conf.c +++ b/bacula/src/dird/run_conf.c @@ -168,7 +168,7 @@ static struct s_kw RunFields[] = { void store_run(LEX *lc, struct res_items *item, int index, int pass) { int i, j, found; - int token, state, state2, code, code2; + int token, state, state2 = 0, code = 0, code2 = 0; int options = lc->options; RUN **run = (RUN **)(item->value); RUN *trun; @@ -190,6 +190,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) found = TRUE; if (lex_get_token(lc, T_ALL) != T_EQUALS) { scan_err1(lc, "Expected an equals, got: %s", lc->str); + /* NOT REACHED */ } token = lex_get_token(lc, T_NAME); switch (RunFields[i].token) { @@ -204,6 +205,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) } if (j != 0) { scan_err1(lc, _("Job level field: %s not found in run record"), lc->str); + /* NOT REACHED */ } break; case 'P': /* Pool */ @@ -212,6 +214,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) if (res == NULL) { scan_err1(lc, "Could not find specified Pool Resource: %s", lc->str); + /* NOT REACHED */ } lrun.pool = (POOL *)res; } @@ -222,6 +225,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) if (res == NULL) { scan_err1(lc, "Could not find specified Storage Resource: %s", lc->str); + /* NOT REACHED */ } lrun.storage = (STORE *)res; } @@ -232,12 +236,14 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) if (res == NULL) { scan_err1(lc, "Could not find specified Messages Resource: %s", lc->str); + /* NOT REACHED */ } lrun.msgs = (MSGS *)res; } break; default: scan_err1(lc, "Expected a keyword name, got: %s", lc->str); + /* NOT REACHED */ break; } /* end switch */ } /* end if strcasecmp */ @@ -265,7 +271,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) set_defaults(); for ( ; token != T_EOL; (token = lex_get_token(lc, T_ALL))) { - int len, pm; + int len, pm = 0; switch (token) { case T_NUMBER: state = s_mday; @@ -295,12 +301,14 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) } if (i != 0) { scan_err1(lc, _("Job type field: %s in run record not found"), lc->str); + /* NOT REACHED */ } break; case T_COMMA: continue; default: scan_err2(lc, _("Unexpected token: %d:%s"), token, lc->str); + /* NOT REACHED */ break; } switch (state) { @@ -332,6 +340,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) case s_time: /* time */ if (!have_at) { scan_err0(lc, _("Time must be preceded by keyword AT.")); + /* NOT REACHED */ } if (!have_hour) { clear_bit(0, lrun.hour); @@ -339,6 +348,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) p = strchr(lc->str, ':'); if (!p) { scan_err0(lc, _("Time logic error.\n")); + /* NOT REACHED */ } *p++ = 0; /* separate two halves */ code = atoi(lc->str); @@ -350,6 +360,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) pm = 1; } else { scan_err0(lc, _("Bad time specification.")); + /* NOT REACHED */ } } else { pm = 0; @@ -360,6 +371,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) } if (code < 0 || code > 23 || code2 < 0 || code2 > 59) { scan_err0(lc, _("Bad time specification.")); + /* NOT REACHED */ } set_bit(code, lrun.hour); lrun.minute = code2; @@ -408,6 +420,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) } if (i != 0 || (state != s_month && state != s_wday)) { scan_err0(lc, _("Invalid month or week day range")); + /* NOT REACHED */ } /* Lookup end of range */ @@ -423,6 +436,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) if (i != 0 || state != state2 || (state2 != s_month && state2 != s_wday) || code == code2) { scan_err0(lc, _("Invalid month or weekday range")); + /* NOT REACHED */ } if (state == s_wday) { if (!have_wday) { @@ -473,6 +487,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) break; default: scan_err0(lc, _("Unexpected run state\n")); + /* NOT REACHED */ break; } } diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index 9f887cbebe..91dc6deff1 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -105,7 +105,7 @@ int showcmd(UAContext *ua, char *cmd) int i, j, type, len; int recurse; char *res_name; - RES *res; + RES *res = NULL; Dmsg1(20, "show: %s\n", ua->UA_sock->msg); diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index cb4dc69b20..4f5922b37a 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -554,6 +554,7 @@ static void user_select_files(TREE_CTX *tree) len = strlen(tree->ua->argk[0]); found = 0; + stat = 0; for (i=0; i<(int)comsize; i++) /* search for command */ if (strncasecmp(tree->ua->argk[0], _(commands[i].key), len) == 0) { stat = (*commands[i].func)(tree->ua, tree); /* go execute command */ diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index 89e542a718..65a826db10 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -428,7 +428,7 @@ static void print_jobs_scheduled(UAContext *ua) } } - Dmsg2(200, "runtime=%d now=%d\n", runtime, now); +// Dmsg2(200, "runtime=%d now=%d\n", runtime, now); if (!found && tom) { localtime_r(&tomorrow, &tm); hour = 0; diff --git a/bacula/src/dird/verify.c b/bacula/src/dird/verify.c index 04642bfa91..699f99ce44 100644 --- a/bacula/src/dird/verify.c +++ b/bacula/src/dird/verify.c @@ -72,7 +72,7 @@ int do_verify(JCR *jcr) char *level; BSOCK *fd; JOB_DBR jr; - JobId_t JobId; + JobId_t JobId = 0; if (!get_or_create_client_record(jcr)) { goto bail_out; @@ -392,7 +392,7 @@ int get_attributes_and_compare_to_catalog(JCR *jcr, JobId_t JobId) * Link name ??? */ while ((n=bget_msg(fd, 0)) > 0 && !job_cancelled(jcr)) { - long file_index, attr_file_index; + long file_index = 0, attr_file_index = 0; int stream; char *attr, *p, *fn; char Opts_MD5[MAXSTRING]; /* Verify Opts or MD5 signature */ diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index 1c9c2da759..6d2fcd2d9d 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -280,6 +280,7 @@ void save_resource(int type, struct res_items *items, int pass) default: printf(_("Unknown resource type %d\n"), type); error = 1; + size = 1; break; } /* Common */ diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index c98766d310..8f77549013 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -247,14 +247,16 @@ lex_tok_to_str(int token) static uint32_t scan_pint(LEX *lf, char *str) { - double dval; + double dval = 0; if (!is_a_number(str)) { scan_err1(lf, "expected a positive integer number, got: %s", str); + /* NOT REACHED */ } else { errno = 0; dval = strtod(str, NULL); if (errno != 0 || dval < 0) { scan_err1(lf, "expected a postive integer number, got: %s", str); + /* NOT REACHED */ } } return (uint32_t)dval; diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 3b1e6d82a1..99c1598e74 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -184,7 +184,7 @@ void store_msgs(LEX *lc, struct res_items *item, int index, int pass) int token; char *cmd; POOLMEM *dest; - int dest_len; + int dest_len; Dmsg2(200, "store_msgs pass=%d code=%d\n", pass, item->code); if (pass == 1) { @@ -205,12 +205,12 @@ void store_msgs(LEX *lc, struct res_items *item, int index, int pass) cmd = res_all.res_msgs.mail_cmd; } dest = get_pool_memory(PM_MESSAGE); - dest_len = 0; dest[0] = 0; + dest_len = 0; /* Pick up comma separated list of destinations */ for ( ;; ) { token = lex_get_token(lc, T_NAME); /* scan destination */ - dest = (char *) check_pool_memory_size(dest, dest_len + lc->str_len + 2); + dest = check_pool_memory_size(dest, dest_len + lc->str_len + 2); if (dest[0] != 0) { strcat(dest, " "); /* separate multiple destinations with space */ dest_len++; @@ -237,7 +237,7 @@ void store_msgs(LEX *lc, struct res_items *item, int index, int pass) dest = get_pool_memory(PM_MESSAGE); /* Pick up a single destination */ token = lex_get_token(lc, T_NAME); /* scan destination */ - dest = check_pool_memory_size(dest, dest_len + lc->str_len + 2); + dest = check_pool_memory_size(dest, lc->str_len + 2); strcpy(dest, lc->str); dest_len = lc->str_len; token = lex_get_token(lc, T_ALL); @@ -269,7 +269,7 @@ void store_msgs(LEX *lc, struct res_items *item, int index, int pass) static void scan_types(LEX *lc, MSGS *msg, int dest_code, char *where, char *cmd) { int i, found, quit, is_not; - int msg_type; + int msg_type = 0; char *str; for (quit=0; !quit;) { @@ -291,6 +291,7 @@ static void scan_types(LEX *lc, MSGS *msg, int dest_code, char *where, char *cmd } if (!found) { scan_err1(lc, "message type: %s not found", str); + /* NOT REACHED */ } if (msg_type == M_MAX+1) { /* all? */ @@ -640,9 +641,10 @@ void parse_config(char *cf) { LEX *lc = NULL; - int token, i, res_type, pass; + int token, i, pass; + int res_type = 0; enum parse_state state = p_none; - struct res_items *items; + struct res_items *items = NULL; int level = 0; /* Make two passes. The first builds the name symbol table, @@ -661,6 +663,7 @@ parse_config(char *cf) } if (token != T_IDENTIFIER) { scan_err1(lc, "Expected a Resource name identifier, got: %s", lc->str); + /* NOT REACHED */ } for (i=0; resources[i].name; i++) if (strcasecmp(resources[i].name, lc->str) == 0) { @@ -672,6 +675,7 @@ parse_config(char *cf) } if (state == p_none) { scan_err1(lc, "expected resource name, got: %s", lc->str); + /* NOT REACHED */ } break; case p_resource: @@ -682,6 +686,7 @@ parse_config(char *cf) case T_IDENTIFIER: if (level != 1) { scan_err1(lc, "not in resource definition: %s", lc->str); + /* NOT REACHED */ } for (i=0; items[i].name; i++) { if (strcasecmp(items[i].name, lc->str) == 0) { @@ -689,6 +694,7 @@ parse_config(char *cf) Dmsg1 (150, "in T_IDENT got token=%s\n", lex_tok_to_str(token)); if (token != T_EQUALS) { scan_err1(lc, "expected an equals, got: %s", lc->str); + /* NOT REACHED */ } Dmsg1(150, "calling handler for %s\n", items[i].name); /* Call item handler */ @@ -701,6 +707,7 @@ parse_config(char *cf) Dmsg2(150, "level=%d id=%s\n", level, lc->str); Dmsg1(150, "Keyword = %s\n", lc->str); scan_err1(lc, "Keyword %s not permitted in this resource", lc->str); + /* NOT REACHED */ } break; @@ -717,10 +724,12 @@ parse_config(char *cf) default: scan_err2(lc, "unexpected token %d %s in resource definition", token, lex_tok_to_str(token)); + /* NOT REACHED */ } break; default: scan_err1(lc, "Unknown parser state %d\n", state); + /* NOT REACHED */ } } if (debug_level > 50 && pass == 2) { diff --git a/bacula/src/lib/tree.c b/bacula/src/lib/tree.c index daeba72ba9..59e1c60091 100755 --- a/bacula/src/lib/tree.c +++ b/bacula/src/lib/tree.c @@ -356,6 +356,9 @@ TREE_NODE *tree_cwd(char *path, TREE_ROOT *root, TREE_NODE *node) } +/* + * Do a relative cwd -- i.e. relative to current node rather than root node + */ TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node) { char *p; @@ -365,9 +368,12 @@ TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node) if (*path == 0) { return node; } + /* Check the current segment only */ p = strchr(path, '/'); if (p) { len = p - path; + } else { + len = strlen(path); } for (cd=node->child; cd; cd=cd->sibling) { if (strncmp(cd->fname, path, len) == 0) { @@ -383,6 +389,7 @@ TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node) return cd; } Dmsg2(100, "recurse tree_relcwd with path=%s, cd=%s\n", p+1, cd->fname); + /* Check the next segment if any */ return tree_relcwd(p+1, root, cd); } diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index 405d32e57c..587697fe7c 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -312,7 +312,7 @@ fstrsch(char *a, char *b) /* folded case search */ char *encode_time(time_t time, char *buf) { struct tm tm; - int n; + int n = 0; if (localtime_r(&time, &tm)) { n = sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", @@ -666,7 +666,7 @@ int run_program(char *prog, int wait, POOLMEM *results) { int stat = ETIME; int chldstatus = 0; - pid_t pid1, pid2; + pid_t pid1, pid2 = 0; int pfd[2]; char *bargv[MAX_ARGV]; int bargc; diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index 48517d3ea5..4e49b90e71 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -245,7 +245,7 @@ int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev) struct timeval tv; struct timezone tz; struct timespec timeout; - int stat, jstat; + int stat = 0, jstat; /* ******FIXME******* put these on config variable */ int min_wait = 60 * 60; int max_wait = 24 * 60 * 60; @@ -386,7 +386,7 @@ volumes for Job=%s.\n"), jcr->Job); */ int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev) { - int stat, jstat; + int stat = 0; /* ******FIXME******* put these on config variable */ int min_wait = 60 * 60; int max_wait = 24 * 60 * 60; @@ -428,7 +428,7 @@ int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev) P(dev->mutex); dev_blocked = dev->dev_blocked; dev->dev_blocked = BST_WAITING_FOR_SYSOP; /* indicate waiting for mount */ - jcr->JobStatus = jstat; + jcr->JobStatus = JS_WaitMount; dir_send_job_status(jcr); for ( ;!job_cancelled(jcr); ) { diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 3ea5449d26..886713392a 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -155,7 +155,6 @@ int main (int argc, char *argv[]) static void do_extract(char *devname, char *where) { - int n; char VolName[100]; char *p; struct stat statp; @@ -284,7 +283,8 @@ static void do_extract(char *devname, char *where) else if (!(status & MT_ONLINE)) Emsg0(M_ERROR_TERM, 0, "Unexpected Tape is Off-line\n"); else - Emsg3(M_ERROR_TERM, 0, "Read error %d on Record Header %s: %s\n", n, dev_name(dev), strerror(errno)); + Emsg3(M_ERROR_TERM, 0, "Read error %d on Record Header %s: %s\n", + status, dev_name(dev), strerror(errno)); } diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index b50fb455bd..e9e3425d28 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -609,7 +609,7 @@ int fsf_dev(DEVICE *dev, int num) { struct mtop mt_com; - int stat; + int stat = 0; char rbuf[1024]; if (dev->fd < 0) { diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 1bee572b4c..7f20bef970 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -612,7 +612,7 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) { uint32_t stat = 0; char PrevVolName[MAX_NAME_LENGTH]; - DEV_BLOCK *label_blk; + DEV_BLOCK *label_blk = NULL; char b1[30], b2[30]; time_t wait_time; @@ -698,7 +698,9 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) jcr->run_time += time(NULL) - wait_time; /* correct run time */ return 1; /* device locked */ } - free_block(label_blk); + if (label_blk) { + free_block(label_blk); + } return 0; /* device locked */ } diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 1f5b4c8c5b..26bd3cbffa 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -104,7 +104,7 @@ void connection_request(void *arg) BSOCK *bs = (BSOCK *)arg; JCR *jcr; int i, found, quit; - int bnet_stat; + int bnet_stat = 0; char name[MAX_NAME_LENGTH]; if (bnet_recv(bs) <= 0) { diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index 36a54278a9..c42bf4c392 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -369,6 +369,7 @@ void save_resource(int type, struct res_items *items, int pass) default: printf("Unknown resource type %d\n", type); error = 1; + size = 1; break; } /* Common */