Changeset: 82aa4c5c76e1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=82aa4c5c76e1
Modified Files:
clients/mapiclient/eventparser.c
clients/mapiclient/eventparser.h
clients/mapiclient/tachograph.c
clients/mapiclient/tomograph.c
Branch: Jul2015
Log Message:
Coverity-inspired fixes.
diffs (192 lines):
diff --git a/clients/mapiclient/eventparser.c b/clients/mapiclient/eventparser.c
--- a/clients/mapiclient/eventparser.c
+++ b/clients/mapiclient/eventparser.c
@@ -50,29 +50,31 @@ clearArguments(void)
}
char *
-stripQuotes(char *currentquery)
-{ char *q, *c, *qry;
- q = qry = (char *) malloc(strlen(currentquery) * 2);
- if( q == NULL){
- fprintf(stderr,"Could not allocate query buffer
of size "SZFMT"\n", strlen(currentquery) * 2);
- exit(-1);
- }
- for (c= currentquery; *c; ){
- if ( strncmp(c,"\\\\t",3) == 0){
- *q++ = '\t';
- c+=3;
- } else
- if ( strncmp(c,"\\\\n",3) == 0){
- *q++ = '\n';
- c+=3;
- } else if ( strncmp(c,"\\\"",2) == 0){
- *q++= '"';
- c+=2;
- } else if ( strncmp(c,"\\\\",2) == 0){
- c+= 2;
- } else *q++ = *c++;
- }
- *q =0;
+stripQuotes(const char *currentquery)
+{
+ const char *c;
+ char *q, *qry;
+ q = qry = (char *) malloc(strlen(currentquery) * 2);
+ if( q == NULL){
+ fprintf(stderr,"Could not allocate query buffer of size
"SZFMT"\n", strlen(currentquery) * 2);
+ exit(-1);
+ }
+ for (c= currentquery; *c; ){
+ if ( strncmp(c,"\\\\t",3) == 0){
+ *q++ = '\t';
+ c+=3;
+ } else
+ if ( strncmp(c,"\\\\n",3) == 0){
+ *q++ = '\n';
+ c+=3;
+ } else if ( strncmp(c,"\\\"",2) == 0){
+ *q++= '"';
+ c+=2;
+ } else if ( strncmp(c,"\\\\",2) == 0){
+ c+= 2;
+ } else *q++ = *c++;
+ }
+ *q =0;
return qry;
}
@@ -228,7 +230,7 @@ eventparser(char *row, EventRecord *ev)
/* scan event record number */
c = row+1;
- if (c == 0)
+ if (*c == 0)
return -2;
ev->eventnr = atoi(c + 1);
@@ -250,6 +252,8 @@ eventparser(char *row, EventRecord *ev)
ev->clkticks += usec;
}
c = strchr(c + 1, '"');
+ if (c == NULL)
+ return -3;
if (ev->clkticks < 0) {
fprintf(stderr, "parser: read negative value "LLFMT"
from\n'%s'\n", ev->clkticks, cc);
}
diff --git a/clients/mapiclient/eventparser.h b/clients/mapiclient/eventparser.h
--- a/clients/mapiclient/eventparser.h
+++ b/clients/mapiclient/eventparser.h
@@ -100,5 +100,5 @@ extern char *monetdb_characteristics;
extern void clearArguments(void);
extern void eventdump(void);
extern int eventparser(char *row, EventRecord *ev);
-extern char *stripQuotes(char *currentquery);
+extern char *stripQuotes(const char *currentquery);
#endif /*_EVENT_PARSER_*/
diff --git a/clients/mapiclient/tachograph.c b/clients/mapiclient/tachograph.c
--- a/clients/mapiclient/tachograph.c
+++ b/clients/mapiclient/tachograph.c
@@ -486,7 +486,7 @@ showBar(int level, lng clk, char *stmt)
} else
if( duration && duration- clk > 0){
rendertime(duration - clk,0);
- printf(" %c%s ETC ", (level == 100? '-':' '),stamp);
+ printf(" %s ETC ", stamp);
stamplen= strlen(stamp)+3;
} else
if( duration && duration- clk < 0){
diff --git a/clients/mapiclient/tomograph.c b/clients/mapiclient/tomograph.c
--- a/clients/mapiclient/tomograph.c
+++ b/clients/mapiclient/tomograph.c
@@ -826,6 +826,8 @@ showcpu(void)
double cpuload[MAXTHREADS];
char *s;
+ for (i = 0; i < MAXTHREADS; i++)
+ cpuload[i] = 0;
fprintf(gnudata, "\nset tmarg 1\n");
fprintf(gnudata, "set bmarg 0\n");
fprintf(gnudata, "set lmarg 10\n");
@@ -863,7 +865,7 @@ showcpu(void)
// paint the heatmap, the load refers the previous time
slot
if( prev >= 0)
for(j=0; j < cpus; j++)
- fprintf(gnudata,"set object %d rectangle from
"LLFMT".0, %d.0 to "LLFMT".0, %d fillcolor rgb \"%s\" fillstyle solid 1.0
noborder\n",
+ fprintf(gnudata,"set object %d
rectangle from "LLFMT".0, %d.0 to "LLFMT".0, %d fillcolor rgb \"%s\" fillstyle
solid 1.0 noborder\n",
object++, box[prev].clkend, j ,
box[i].clkstart, (j+1) , getHeatColor(cpuload[j]) );
prev = i;
}
@@ -1173,7 +1175,7 @@ updatecolormap(int idx)
colors[fnd].mod = mod?strdup(mod): 0;
colors[fnd].fcn = strdup(fcn);
if( debug)
- fprintf(stderr,"-- Added function #%d: %s.%s\n", fnd,
(mod?mod:""), fcn);
+ fprintf(stderr,"-- Added function #%d: %s.%s\n", fnd,
mod, fcn);
}
colors[fnd].freq++;
@@ -1542,7 +1544,7 @@ update(char *line, EventRecord *ev)
box[idx].stmt = ev->stmt;
box[idx].fcn = ev->fcn ? strdup(ev->fcn) : strdup("");
if(ev->fcn && strstr(ev->fcn,"querylog.define") ){
- currentquery =
stripQuotes(strdup(malarguments[malretc]));
+ currentquery = stripQuotes(malarguments[malretc]);
fprintf(stderr,"-- page %d :%s\n",atlaspage,
currentquery);
}
return;
@@ -1624,7 +1626,6 @@ main(int argc, char **argv)
char *user = NULL;
char *password = NULL;
char buf[BUFSIZ], *e, *response;
- FILE *trace = NULL;
FILE *inpfd;
int colormap=0;
EventRecord event;
@@ -1659,7 +1660,7 @@ main(int argc, char **argv)
while (1) {
int option_index = 0;
int c = getopt_long(argc, argv,
"d:u:p:P:h:?T:i:r:s:q:o:c:Db:A:m",
- long_options, &option_index);
+ long_options, &option_index);
if (c == -1)
break;
switch (c) {
@@ -1772,11 +1773,13 @@ main(int argc, char **argv)
/* reprocess an existing profiler trace, possibly producing the trace
split */
printf("-- Output directed towards %s%s_*\n", dirpath, prefix);
+ if (
#ifdef NATIVE_WIN32
- if( _mkdir(dirpath) < 0 && errno != EEXIST){
+ _mkdir(dirpath) < 0
#else
- if( mkdir(dirpath,0755) < 0 && errno != EEXIST) {
+ mkdir(dirpath,0755) < 0
#endif
+ && errno != EEXIST) {
fprintf(stderr,"Failed to create dirpath '%s'\n",dirpath);
exit(-1);
}
@@ -1904,10 +1907,8 @@ main(int argc, char **argv)
update(response, &event);
if (debug )
fprintf(stderr, "PARSE %d:%s\n", i,
response);
- if( trace && i >=0 && capturing)
- fprintf(trace,"%s\n",response);
- response = e + 1;
- }
+ response = e + 1;
+ }
/* handle last line in buffer */
if (*response) {
if (debug)
@@ -1921,7 +1922,7 @@ main(int argc, char **argv)
if( !inputfile)
doQ("profiler.stop();");
-stop_disconnect:
+ stop_disconnect:
if( !inputfile) {
mapi_disconnect(dbh);
printf("-- connection with server %s closed\n", uri ? uri :
host);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list