Skip to content

Commit

Permalink
Merge pull request #8 from stevenhoneyman/master
Browse files Browse the repository at this point in the history
Fix all of the -Wformat-security warnings
  • Loading branch information
bcarrier committed Sep 30, 2014
2 parents 90393b6 + 64dea0c commit 72f32cb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/dig.cpp
Expand Up @@ -2722,15 +2722,15 @@ int init_threading_model(struct scalpelState *state) {
if(pthread_mutex_init(&workavailable[i], 0)) {
//return SCALPEL_ERROR_PTHREAD_FAILURE;
std::string msg ("COULDN'T CREATE MUTEX\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}

pthread_mutex_lock(&workavailable[i]);

if(pthread_mutex_init(&workcomplete[i], 0)) {
std::string msg ("COULDN'T CREATE MUTEX\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}

Expand All @@ -2743,7 +2743,7 @@ int init_threading_model(struct scalpelState *state) {
(&searchthreads[i], NULL, &threadedFindAll, &threadargs[i])) {
//return SCALPEL_ERROR_PTHREAD_FAILURE;
std::string msg ("COULDN'T CREATE THREAD\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.cpp
Expand Up @@ -452,7 +452,7 @@ void handleError(struct scalpelState *state, int error)
msg = "Scalpel will write only to empty output directories to avoid\n"
"mixing the output from multiple carving operations.\n"
"Please specify a different output directory or delete the specified\noutput directory.\n";
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
closeAuditFile(state->auditFile);
throw std::runtime_error(msg);
break;
Expand All @@ -461,7 +461,7 @@ void handleError(struct scalpelState *state, int error)
// fatal--unable to write files, which may mean that disk space is exhausted.
msg = "Scalpel was unable to write output files and will abort.\n"
"This error generally indicates that disk space is exhausted.\n";
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
closeAuditFile(state->auditFile);
throw std::runtime_error(msg);
break;
Expand Down
38 changes: 19 additions & 19 deletions src/prioque.cpp
Expand Up @@ -152,13 +152,13 @@ void nolock_add_to_queue(Queue * q, void *element, int priority)
new_element = (Queue_element) malloc(sizeof(struct _Queue_element));
if(new_element == 0) {
std::string msg ("Malloc failed in function add_to_queue()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
new_element->info = (void *)malloc(q->elementsize);
if(new_element->info == 0) {
std::string msg("Malloc failed in function add_to_queue()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}

Expand Down Expand Up @@ -224,7 +224,7 @@ void remove_from_front(Queue * q, void *element)
#if defined(CONSISTENCY_CHECKING)
if(q->queue == 0) {
std::string msg("Malloc failed in function remove_from_front()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand Down Expand Up @@ -256,7 +256,7 @@ void peek_at_current(Queue * q, void *element)
#if defined(CONSISTENCY_CHECKING)
if(q->queue == 0 || q->current == 0) {
std::string msg("NULL pointer in function peek_at_current()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand All @@ -281,7 +281,7 @@ void *pointer_to_current(Queue * q)
#if defined(CONSISTENCY_CHECKING)
if(q->queue == 0 || q->current == 0) {
std::string msg("NULL pointer in function pointer_to_current()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand All @@ -308,7 +308,7 @@ int current_priority(Queue * q)
#if defined(CONSISTENCY_CHECKING)
if(q->queue == 0 || q->current == 0) {
std::string msg("NULL pointer in function peek_at_current()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand All @@ -333,7 +333,7 @@ void update_current(Queue * q, void *element)
#if defined(CONSISTENCY_CHECKING)
if(q->queue == 0 || q->current == 0) {
std::string msg("Malloc failed in function update_current()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand All @@ -357,7 +357,7 @@ void delete_current(Queue * q)
#if defined(CONSISTENCY_CHECKING)
if(q->queue == 0 || q->current == 0) {
std::string msg("Malloc failed in function delete_current()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand Down Expand Up @@ -411,12 +411,12 @@ void nolock_next_element(Queue * q)
#if defined(CONSISTENCY_CHECKING)
if(q->queue == 0) {
std::string msg("NULL pointer in function next_element()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else if(q->current == 0) {
std::string msg("Advance past end in NULL pointer in function next_element()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand Down Expand Up @@ -483,14 +483,14 @@ void copy_queue(Queue * q1, Queue * q2)

if(new_element == 0) {
std::string msg("Malloc failed in function copy_queue()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}

new_element->info = (void *)malloc(q1->elementsize);
if(new_element->info == 0) {
std::string msg("Malloc failed in function copy_queue()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
memcpy(new_element->info, temp->info, q1->elementsize);
Expand Down Expand Up @@ -600,7 +600,7 @@ void local_peek_at_current(Context * ctx, void *element)
#if defined(CONSISTENCY_CHECKING)
if(ctx->queue == 0 || ctx->current == 0) {
std::string msg("NULL pointer in function peek_at_current()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand All @@ -626,7 +626,7 @@ void *local_pointer_to_current(Context * ctx)
#if defined(CONSISTENCY_CHECKING)
if(ctx->queue == 0 || ctx->current == 0) {
std::string msg("NULL pointer in function pointer_to_current()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand All @@ -653,7 +653,7 @@ int local_current_priority(Context * ctx)
#if defined(CONSISTENCY_CHECKING)
if(ctx->queue == 0 || ctx->current == 0) {
std::string msg("NULL pointer in function peek_at_current()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand All @@ -677,7 +677,7 @@ void local_update_current(Context * ctx, void *element)
#if defined(CONSISTENCY_CHECKING)
if(ctx->queue == 0 || ctx->current == 0) {
std::string msg("NULL pointer in function update_current()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand All @@ -701,7 +701,7 @@ void local_delete_current(Context * ctx)
#if defined(CONSISTENCY_CHECKING)
if(ctx->queue == 0 || ctx->current == 0) {
std::string msg("NULL pointer in function delete_current()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand Down Expand Up @@ -755,12 +755,12 @@ void local_nolock_next_element(Context * ctx)
#if defined(CONSISTENCY_CHECKING)
if(ctx->queue == 0) {
std::string msg("NULL pointer in function next_element()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else if(ctx->current == 0) {
std::string msg("Advance past end in NULL pointer in function next_element()\n");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/scalpel.cpp
Expand Up @@ -118,7 +118,7 @@ int extractSearchSpecData(struct scalpelState *state,
ss << "ERROR: GPU search for regex headers is not supported!\n";
ss << "Please modify the config file for non-regex headers only.\n";
std::string msg = ss.str();
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
#endif

Expand Down Expand Up @@ -152,7 +152,7 @@ int extractSearchSpecData(struct scalpelState *state,
ss << "ERROR: GPU search for regex footers is not supported!\n";
ss << "Please modify the config file for non-regex footers only.\n";
std::string msg = ss.str();
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/syncqueue.cpp
Expand Up @@ -71,7 +71,7 @@ syncqueue_t *syncqueue_init(const char *qname, unsigned long size) {
q = (syncqueue_t *) calloc(1, sizeof(syncqueue_t));
if(q == NULL) {
std::string msg("Couldn't create queue! Aborting.");
fprintf(stderr, msg.c_str());
fprintf(stderr, "%s", msg.c_str());
throw std::runtime_error(msg);
}

Expand Down

0 comments on commit 72f32cb

Please sign in to comment.