Skip to content

Commit

Permalink
Fix some more problems reported by coverity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 839923a commit 70ea7db
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 50 deletions.
4 changes: 3 additions & 1 deletion src/cats/sql_get.c
Expand Up @@ -657,6 +657,7 @@ bool db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr)
}
sql_free_result(mdb);
}

if (ok) {
uint32_t NumVols;
Mmsg(mdb->cmd, "SELECT count(*) from Media WHERE PoolId=%s",
Expand All @@ -665,11 +666,12 @@ bool db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr)
Dmsg2(400, "Actual NumVols=%d Pool NumVols=%d\n", NumVols, pdbr->NumVols);
if (NumVols != pdbr->NumVols) {
pdbr->NumVols = NumVols;
db_update_pool_record(jcr, mdb, pdbr);
ok = db_update_pool_record(jcr, mdb, pdbr);
}
} else {
Mmsg(mdb->errmsg, _("Pool record not found in Catalog.\n"));
}

db_unlock(mdb);
return ok;
}
Expand Down
10 changes: 6 additions & 4 deletions src/cats/sql_update.c
Expand Up @@ -120,8 +120,7 @@ bool db_update_job_start_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
}

/*
* Update Long term statistics with all jobs that were run before
* age seconds
* Update Long term statistics with all jobs that were run before age seconds
*/
int db_update_stats(JCR *jcr, B_DB *mdb, utime_t age)
{
Expand All @@ -133,8 +132,11 @@ int db_update_stats(JCR *jcr, B_DB *mdb, utime_t age)
db_lock(mdb);

Mmsg(mdb->cmd, fill_jobhisto, ed1);
QUERY_DB(jcr, mdb, mdb->cmd); /* TODO: get a message ? */
rows = sql_affected_rows(mdb);
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
rows = sql_affected_rows(mdb);
} else {
rows = -1;
}

db_unlock(mdb);
return rows;
Expand Down
21 changes: 15 additions & 6 deletions src/dird/ua_output.c
Expand Up @@ -379,12 +379,13 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)

/* List Base files */
} else if (bstrcasecmp(ua->argk[i], NT_("basefiles"))) {
/* TODO: cleanup this block */
for (j=i+1; j<ua->argc; j++) {
if (bstrcasecmp(ua->argk[j], NT_("ujobid")) && ua->argv[j]) {
bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH);
jr.JobId = 0;
db_get_job_record(ua->jcr, ua->db, &jr);
if (!db_get_job_record(ua->jcr, ua->db, &jr)) {
continue;
}
jobid = jr.JobId;
} else if (bstrcasecmp(ua->argk[j], NT_("jobid")) && ua->argv[j]) {
jobid = str_to_int64(ua->argv[j]);
Expand All @@ -403,7 +404,9 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
if (bstrcasecmp(ua->argk[j], NT_("ujobid")) && ua->argv[j]) {
bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH);
jr.JobId = 0;
db_get_job_record(ua->jcr, ua->db, &jr);
if (!db_get_job_record(ua->jcr, ua->db, &jr)) {
continue;
}
jobid = jr.JobId;
} else if (bstrcasecmp(ua->argk[j], NT_("jobid")) && ua->argv[j]) {
jobid = str_to_int64(ua->argv[j]);
Expand All @@ -422,7 +425,9 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
if (bstrcasecmp(ua->argk[j], NT_("ujobid")) && ua->argv[j]) {
bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH);
jr.JobId = 0;
db_get_job_record(ua->jcr, ua->db, &jr);
if (!db_get_job_record(ua->jcr, ua->db, &jr)) {
continue;
}
jobid = jr.JobId;
} else if (bstrcasecmp(ua->argk[j], NT_("jobid")) && ua->argv[j]) {
jobid = str_to_int64(ua->argv[j]);
Expand All @@ -444,7 +449,9 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
if (bstrcasecmp(ua->argk[j], NT_("ujobid")) && ua->argv[j]) {
bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH);
jr.JobId = 0;
db_get_job_record(ua->jcr, ua->db, &jr);
if (!db_get_job_record(ua->jcr, ua->db, &jr)) {
continue;
}
jobid = jr.JobId;
} else if (bstrcasecmp(ua->argk[j], NT_("jobid")) && ua->argv[j]) {
jobid = str_to_int64(ua->argv[j]);
Expand Down Expand Up @@ -482,7 +489,9 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
if (bstrcasecmp(ua->argk[j], NT_("ujobid")) && ua->argv[j]) {
bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH);
jr.JobId = 0;
db_get_job_record(ua->jcr, ua->db, &jr);
if (!db_get_job_record(ua->jcr, ua->db, &jr)) {
continue;
}
jobid = jr.JobId;
} else if (bstrcasecmp(ua->argk[j], NT_("jobid")) && ua->argv[j]) {
jobid = str_to_int64(ua->argv[j]);
Expand Down
21 changes: 13 additions & 8 deletions src/dird/ua_purge.c
Expand Up @@ -870,12 +870,15 @@ bool mark_media_purged(UAContext *ua, MEDIA_DBR *mr)
bstrcmp(mr->VolStatus, "Full") ||
bstrcmp(mr->VolStatus, "Used") ||
bstrcmp(mr->VolStatus, "Error");

if (status) {
bstrncpy(mr->VolStatus, "Purged", sizeof(mr->VolStatus));
set_storageid_in_mr(NULL, mr);

if (!db_update_media_record(jcr, ua->db, mr)) {
return false;
}

pm_strcpy(jcr->VolumeName, mr->VolumeName);
generate_plugin_event(jcr, bDirEventVolumePurged);

Expand All @@ -888,16 +891,15 @@ bool mark_media_purged(UAContext *ua, MEDIA_DBR *mr)
memset(&newpr, 0, sizeof(newpr));
newpr.PoolId = mr->RecyclePoolId;
oldpr.PoolId = mr->PoolId;
if ( db_get_pool_record(jcr, ua->db, &oldpr)
&& db_get_pool_record(jcr, ua->db, &newpr))
{
if (db_get_pool_record(jcr, ua->db, &oldpr) &&
db_get_pool_record(jcr, ua->db, &newpr)) {
/*
* Check if destination pool size is ok
*/
if (newpr.MaxVols > 0 && newpr.NumVols >= newpr.MaxVols) {
ua->error_msg(_("Unable move recycled Volume in full "
"Pool \"%s\" MaxVols=%d\n"),
newpr.Name, newpr.MaxVols);
"Pool \"%s\" MaxVols=%d\n"),
newpr.Name, newpr.MaxVols);

} else { /* move media */
update_vol_pool(ua, newpr.Name, mr, &oldpr);
Expand All @@ -910,13 +912,16 @@ bool mark_media_purged(UAContext *ua, MEDIA_DBR *mr)
/*
* Send message to Job report, if it is a *real* job
*/
if (jcr && jcr->JobId > 0) {
Jmsg(jcr, M_INFO, 0, _("All records pruned from Volume \"%s\"; marking it \"Purged\"\n"),
mr->VolumeName);
if (jcr->JobId > 0) {
Jmsg(jcr, M_INFO, 0,
_("All records pruned from Volume \"%s\"; marking it \"Purged\"\n"),
mr->VolumeName);
}

return true;
} else {
ua->error_msg(_("Cannot purge Volume with VolStatus=%s\n"), mr->VolStatus);
}

return bstrcmp(mr->VolStatus, "Purged");
}
18 changes: 10 additions & 8 deletions src/filed/fd_plugins.c
Expand Up @@ -212,8 +212,7 @@ static inline bRC trigger_plugin_event(JCR *jcr, bEventType eventType, bEvent *e
b_plugin_ctx *b_ctx = (b_plugin_ctx *)ctx->bContext;

Dmsg0(50, "eventType == bEventEndRestoreJob\n");
if (ctx && ctx->plugin &&
b_ctx && b_ctx->restoreFileStarted) {
if (b_ctx && b_ctx->restoreFileStarted) {
plug_func(ctx->plugin)->endRestoreFile(ctx);
}

Expand Down Expand Up @@ -268,7 +267,9 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value, bool rev
rop = (restore_object_pkt *)value;
if (*rop->plugin_name) {
name = rop->plugin_name;
get_plugin_name(jcr, name, &len);
if (!get_plugin_name(jcr, name, &len)) {
return;
}
}
}
break;
Expand Down Expand Up @@ -1079,17 +1080,18 @@ bool plugin_name_stream(JCR *jcr, char *name)
*/
int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
{
bpContext *ctx = jcr->plugin_ctx;
b_plugin_ctx *b_ctx = (b_plugin_ctx *)jcr->plugin_ctx->bContext;
Plugin *plugin = ctx->plugin;
struct restore_pkt rp;
int flags;
int ret;
int status;
Plugin *plugin;
struct restore_pkt rp;
bpContext *ctx = jcr->plugin_ctx;
b_plugin_ctx *b_ctx = (b_plugin_ctx *)jcr->plugin_ctx->bContext;

if (!plugin || !ctx || !set_cmd_plugin(bfd, jcr) || jcr->is_job_canceled()) {
if (!ctx || !set_cmd_plugin(bfd, jcr) || jcr->is_job_canceled()) {
return CF_ERROR;
}
plugin = ctx->plugin;

rp.pkt_size = sizeof(rp);
rp.pkt_end = sizeof(rp);
Expand Down
31 changes: 16 additions & 15 deletions src/findlib/bfile.c
Expand Up @@ -1181,24 +1181,25 @@ int bclose(BFILE *bfd)
status = plugin_bclose(bfd);
bfd->fid = -1;
bfd->cmd_plugin = false;
}

if (bfd->fid == -1) {
return 0;
}
} else {
if (bfd->fid == -1) {
return 0;
}
#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
if (bfd->m_flags & O_RDONLY) {
fdatasync(bfd->fid); /* sync the file */
/* Tell OS we don't need it any more */
posix_fadvise(bfd->fid, 0, 0, POSIX_FADV_DONTNEED);
}
if (bfd->m_flags & O_RDONLY) {
fdatasync(bfd->fid); /* sync the file */
/* Tell OS we don't need it any more */
posix_fadvise(bfd->fid, 0, 0, POSIX_FADV_DONTNEED);
}
#endif

/* Close normal file */
status = close(bfd->fid);
bfd->berrno = errno;
bfd->fid = -1;
bfd->cmd_plugin = false;
/* Close normal file */
status = close(bfd->fid);
bfd->berrno = errno;
bfd->fid = -1;
bfd->cmd_plugin = false;
}

return status;
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/bregex.c
Expand Up @@ -1159,7 +1159,9 @@ const char *re_compile_pattern(regex_t * bufp, unsigned char *regex)
break;
case Rquote:
set_error("Rquote");
/*NOTREACHED*/ case Rbol:
/* NOTREACHED */
break;
case Rbol:
if (!beginning_context) {
if (regexp_context_indep_ops)
goto op_error;
Expand Down
1 change: 1 addition & 0 deletions src/ndmp/ndma_cops_robot.c
Expand Up @@ -333,6 +333,7 @@ ndmca_op_unload_tape (struct ndm_session *sess)
/* best effort */
rc = ndmca_op_mtio (sess, job->use_eject
? NDMP9_MTIO_OFF : NDMP9_MTIO_REW);
if (rc) return rc; /* already tattled -- NOT */
}

if (job->to_addr_given) {
Expand Down
2 changes: 1 addition & 1 deletion src/ndmp/ndma_data_fh.c
Expand Up @@ -67,7 +67,7 @@ ndmda_fh_commission (struct ndm_session *sess)
da->fhh_buf = NDMOS_API_MALLOC (NDMDA_N_FHH_BUF);
if (!da->fhh_buf)
return -1;
ndmfhh_commission (fhh, da->fhh_buf, sizeof da->fhh_buf);
ndmfhh_commission (fhh, da->fhh_buf, sizeof *da->fhh_buf);

return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions src/ndmp/ndma_image_stream.c
Expand Up @@ -890,7 +890,6 @@ ndmis_tcp_listen (struct ndm_session *sess, struct ndmp9_addr *listen_addr)
* We found a connection to use for determining
* what IP address to offer.
*/
what = "getsockname-ctrl";
len = sizeof c_sa;
if (getsockname (ndmconn_fileno(conn), &c_sa, &len) < 0) {
/* we'll try the fallback rules */
Expand Down Expand Up @@ -1009,7 +1008,6 @@ ndmis_tcp_accept (struct ndm_session *sess)

fail:
ndmalogf (sess, 0, 2, "ndmis_tcp_accept(): %s failed", what);
if (accept_sock >= 0) close (accept_sock);

return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ndmp/ndma_listmgmt.c
Expand Up @@ -229,7 +229,7 @@ ndma_store_nlist (struct ndm_nlist_table *nlist, ndmp9_name *nl)

entry = NDMOS_API_MALLOC (sizeof(struct ndm_nlist_entry));
if (!entry)
goto bail_out;
return NULL;

NDMOS_MACRO_ZEROFILL (entry);

Expand Down
1 change: 0 additions & 1 deletion src/ndmp/ndma_tape.c
Expand Up @@ -614,7 +614,6 @@ ndmta_write_quantum (struct ndm_session *sess)
return did_something - 1;
}
if (done_count != count) {
n_read = done_count;
goto again;
}
ta->tb_blockno = want_blockno;
Expand Down
3 changes: 2 additions & 1 deletion src/ndmp/ndml_conn.c
Expand Up @@ -933,12 +933,13 @@ ndmconn_sys_read (struct ndmconn *conn, char *buf, unsigned len)
rc = read (conn->chan.fd, buf, len);

ndmconn_snoop (conn, 8, "read=%d len=%d", rc, len);
ndmconn_hex_dump (conn, buf, rc);

if (rc <= 0) {
conn->chan.eof = 1;
if (rc < 0)
conn->chan.error = 1;
} else {
ndmconn_hex_dump (conn, buf, rc);
}

return rc;
Expand Down
1 change: 1 addition & 0 deletions src/ndmp/smc_parse.c
Expand Up @@ -155,6 +155,7 @@ smc_parse_element_status_data (
p2 += SMC_VOL_TAG_LEN;
}
if (edp->AVolTag) {
p2 = (unsigned char *) &red->alternate_vol_tag;
smc_parse_volume_tag ((void*)p2,
&edp->alternate_vol_tag);
p2 += SMC_VOL_TAG_LEN;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/filed/bpipe-fd.c
Expand Up @@ -320,12 +320,13 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp)
{
time_t now;
struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext;
struct plugin_ctx *p_ctx;

if (plugin_has_all_arguments(ctx) != bRC_OK) {
return bRC_Error;
}

p_ctx = (struct plugin_ctx *)ctx->pContext;
if (!p_ctx) {
return bRC_Error;
}
Expand Down

0 comments on commit 70ea7db

Please sign in to comment.