Hello,
I really only dabble in programming, but I like to try to do things the
right way. So I'm trying out splint on a little contest problem. I think
I've understood and accounted for the other warnings I received, but
there's one left I don't understand. I'll just quote context, but the
full text of the source is at http://www.sophrosune.org/grants.c if that
helps.
The code takes sets of inputs and stores the results for each input as a
string in one row of results (which is a char **). Each time through the
process, memory for a new row is allocated with
results = realloc(results, (numInputs*sizeof(char *)));
NULLCHECK(results);
(line 99) results[numInputs - 1] = calloc((size_t)(3*N+1),sizeof(char));
NULLCHECK(results[numInputs - 1]);
Shortly after that comes the core of the processing function, which
steps through a circular queue and appends to results[] whenever someone
leaves the queue...
while (true) {
pay(cur);
if (cur->paid == 40) {
prev->next = cur->next;
(void)snprintf(str, 3, "%3d", cur->id);
strcat(results[numInputs - 1], str);
if (cur == prev) break;
free(cur);
cur = prev->next;
} else {
prev = cur;
cur = cur->next;
}
(line 140) }
Splint complains...
grants.c(140,2): Storage results[] reachable from global is fresh
(should be unqualified)
Storage derivable from a parameter does not match the alias kind
expected for the formal parameter. (Use -compmempass to inhibit warning)
grants.c(99,2): Fresh storage results[] created
Now, as I said, I'm not really a programmer so I'm probably missing
something. But I don't get the message. I see that fresh storage is
created at line 99, but the process can't return until a string is
assigned there (in the strcat line). What am I missing, or how do I tell
splint this is OK?
Thanks,
Todd
_______________________________________________
splint-discuss mailing list
[email protected]
http://www.cs.Virginia.EDU/mailman-2.1.5/listinfo/splint-discuss