Skip to content

Commit

Permalink
ADD: travis ci
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk committed Mar 9, 2020
1 parent a75bb8d commit 3232a6f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 8 deletions.
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
dist: trusty
language: c++
os:
- linux
sudo: yes
compiler:
- gcc

stages:
- analysis
- build
- test

jobs:
include:
- stage: analysis
name: Static check the source code and lint
install:
- sudo apt-get install -y cppcheck
script:
make lint

- stage: build
name: build the tcpkit
install:
- sudo apt-get install flex bison
script:
make

- stage: build
name: unittest
script:
make test
5 changes: 5 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ deps: nop
@cd ../deps/libpcap/ && ./configure --enable-dbus=no --without-libnl && make
@cd ../deps/lua/src && make a

lint:
sh cppcheck.sh
test:

clean:
- rm -rf $(PROG) dep.mk *.o
@cd ../deps/libpcap/ && make clean
@cd ../deps/lua/src/ && make clean

nop:

install:
Expand Down
7 changes: 7 additions & 0 deletions src/cppcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
CHECK_TYPES="warning,performance,portability,information,missingInclude"
STANDARD=c89
ERROR_EXITCODE=1
LANG=c
FILES=$(ls *.h *.c|grep -v cJSON|awk '{printf $0" "}')
cppcheck --enable=${CHECK_TYPES} -U__GNUC__ -x ${LANG} ${FILES} --std=${STANDARD} --error-exitcode=${ERROR_EXITCODE}
10 changes: 8 additions & 2 deletions src/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,24 @@ int hashtable_del(hashtable *ht, char *key) {
void **hashtable_values(hashtable *ht, int *cnt) {
int i, cap = 0;
entry *e;
void **values = NULL;
void **values = NULL, **new_values;

*cnt = 0;
for (i = 0; i < ht->nbucket; i++) {
e = ht->buckets[i];
while(e) {
if (!values) {
values = malloc(sizeof(void *));
if (!values) return NULL;
cap = 1;
} else if (*cnt == cap) {
cap *= 2;
values = realloc(values, sizeof(void *) * cap);
new_values = realloc(values, sizeof(void *) * cap);
if (!new_values) {
return values;
} else {
values = new_values;
}
}
values[*cnt] = e->value;
*cnt += 1;
Expand Down
1 change: 1 addition & 0 deletions src/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* GNU General Public License for more details.
*
**/
#include <time.h>
#include <stdlib.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
Expand Down
5 changes: 4 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ struct server *server_create(struct options *opts, char *err) {
srv->stats_tid = 0;
srv->stopped = 0;
sniffer = sniffer_create(opts, err);
if (!sniffer) return NULL;
if (!sniffer) {
free(srv);
return NULL;
}
srv->sniffer = sniffer;

if (!opts->offline_file && opts->save_file) {
Expand Down
15 changes: 10 additions & 5 deletions src/tcpkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,17 @@ struct options *parse_options(int argc, char **argv) {
if (!opts->filter) {
opts->filter = strdup(argv[i]);
} else {
char *tmp;
int new_size, old_size = strlen(opts->filter);
// add 2 for white space and terminal char
new_size = old_size+strlen(argv[i])+2;
opts->filter = realloc(opts->filter, new_size);
opts->filter[old_size++] = ' ';
memcpy(opts->filter+old_size, argv[i], strlen(argv[i]));
opts->filter[new_size-1] = '\0';
tmp = realloc(opts->filter, new_size);
if (tmp) {
opts->filter = tmp;
opts->filter[old_size++] = ' ';
memcpy(opts->filter+old_size, argv[i], strlen(argv[i]));
opts->filter[new_size-1] = '\0';
}
}
}
}
Expand All @@ -149,7 +153,8 @@ struct options *parse_options(int argc, char **argv) {

invalid:
log_message(FATAL, "Invalid option \"%s\" or option argument missing",argv[i]);
return 0;
free_options(opts);
return NULL;
}

int main(int argc, char **argv) {
Expand Down

0 comments on commit 3232a6f

Please sign in to comment.