Skip to content

Commit

Permalink
* add travis and coverity
Browse files Browse the repository at this point in the history
* fix outstanding defects aka memleaks
  • Loading branch information
Helmut Januschka authored and hjanuschka committed Apr 21, 2015
1 parent 1890bf7 commit 5489636
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: c
env:
global:
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created a
# via the "travis encrypt" command using the project repo's public key
- secure: "kF/CFYVefdvGgyLaGwcLH+q8a60WWGIUB7Jlx+B+Xjgk2Jd3Mebz3xevjWhv11eB/Y1oaotLDayMJc/xYiOnfVKTEztR00geqa6Oo7c9ZxN1/FWBip4JKlCo1l8O5vMj8E30r/AS61S7KW+5DRy5a+l7XcCltJHymXkpNuCTeHQ="

addons:
coverity_scan:
project:
name: "hjanuschka/progress.h"

This comment has been minimized.

Copy link
@stephenmathieson

stephenmathieson Apr 22, 2015

shouldn't this be jwerle/progress.c?

This comment has been minimized.

Copy link
@jwerle

jwerle Apr 22, 2015

Owner

heh not sure. I'm sure it is supposed to be

This comment has been minimized.

Copy link
@hjanuschka

hjanuschka Apr 22, 2015

Contributor

sorry - you are right the .travis.yml needs to be modified.

  • repo name
  • coverity secure token

@jwerle - can you do that - or should i send another PR

This comment has been minimized.

Copy link
@hjanuschka

hjanuschka Apr 22, 2015

Contributor

or just drop the whole .travis.yml file :/

description: "clib progress bar"
notification_email: helmut@januschka.com
build_command_prepend: rm -vf test-progress
build_command: make
branch_pattern: coverity_scan

before_script:
- make

script:
- ./test-progress
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

CFLAGS = -std=c99 -I. -Wall
CFLAGS = -std=c99 -I. -Wall -g

all: clean test
@:
Expand Down
41 changes: 29 additions & 12 deletions progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ static char *
replace_str (char *strbuf, char *strold, char *strnew) {
char *strret, *p = NULL;
char *posnews, *posold;
size_t szold = strlen(strold);
size_t sznew = strlen(strnew);
size_t n = 1;

if (!strbuf) return NULL;
if (!strold || !strnew || !(p = strstr(strbuf, strold)))
return strdup(strbuf);

size_t szold = strlen(strold);
size_t sznew = strlen(strnew);
size_t n = 1;



while (n > 0) {
if (!(p = strstr(p+1, strold))) break;
else n++;
Expand All @@ -58,6 +61,7 @@ replace_str (char *strbuf, char *strold, char *strnew) {
}

strcpy(posnews, posold);
free(strbuf);
return strret;
}

Expand Down Expand Up @@ -89,7 +93,7 @@ progress_event_new (progress_event_type_t type) {

void
progress_event_free (progress_event_t *event) {
//if (event) free(event);
if (event) free(event);
}

progress_event_listener_t *
Expand All @@ -105,7 +109,8 @@ void
progress_event_listener_free (progress_event_listener_t *listener) {
if (!listener) return;
if (listener->data) progress_data_free(listener->data);
// if (listener->event) progress_event_free(listener->event);
//if (listener->event) progress_event_free(listener->event);
//free(listener);
}

progress_data_t *
Expand All @@ -124,9 +129,11 @@ progress_data_free (progress_data_t *data) {

bool
progress_on (progress_t *progress, progress_event_type_t event, progress_cb_t cb) {
progress_event_listener_t *listener = progress_event_listener_new(progress_event_new(event), cb);
progress_event_t * ev = progress_event_new(event);
progress_event_listener_t *listener = progress_event_listener_new(ev, cb);
if (!listener) return false;
progress->listeners[progress->listener_count++] = *listener;
memcpy(&progress->listeners[progress->listener_count++], listener, sizeof(progress_event_listener_t));
free(listener);
return true;
}

Expand Down Expand Up @@ -175,20 +182,29 @@ progress_change_value (progress_t *progress, int value, bool increment) {
progress_event_t *event = progress_event_new(PROGRESS_EVENT_START);
progress_data_t *data = progress_data_new(progress, value);
progress_emit(progress, event, data);

free(event);
free(data);
}

progress->elapsed = difftime(now, progress->start);
progress_event_t *event = progress_event_new(PROGRESS_EVENT_PROGRESS);
progress_data_t *data = progress_data_new(progress, value);
progress_emit(progress, event, data);

free(event);
free(data);


if (progress->value >= progress->total) {
progress->finished = true;
progress->value = progress->total;
progress_event_t *event = progress_event_new(PROGRESS_EVENT_END);
progress_data_t *data = progress_data_new(progress, value);
progress_emit(progress, event, data);
progress_free(progress);

free(event);
free(data);
}

return true;
Expand All @@ -204,8 +220,8 @@ progress_write (progress_t *progress) {
double elapsed = progress->elapsed;
char *fmt = malloc(512 * sizeof(char));
char *bar = malloc((complete + incomplete) * sizeof(char));
char *percent_str = malloc(sizeof(char));
char *elapsed_str = malloc(sizeof(char));
char *percent_str = malloc(sizeof(char)*20);
char *elapsed_str = malloc(sizeof(char)*20);

sprintf(percent_str, "%d%%", percent);
sprintf(elapsed_str, "%.1fs", elapsed);
Expand Down Expand Up @@ -246,10 +262,11 @@ void
progress_free (progress_t *progress) {
int i;
for (i = 0; i < progress->listener_count; ++i) {
progress_event_listener_free(&progress->listeners[i]);
progress_event_free(progress->listeners[i].event);

}

// free(progress);
free(progress);
}

void
Expand Down

0 comments on commit 5489636

Please sign in to comment.