IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Opened 21 years ago

Closed 21 years ago

Last modified 21 years ago

#361 closed defect (fixed)

psMetadataItemAllocV over-allocates memory for comment

Reported by: eugene Owned by: robert.desonia@…
Priority: high Milestone:
Component: types Version: 0.5.0
Severity: normal Keywords:
Cc:

Description

the specific problem is in lines 187-194:

Allocate and set metadata item comment
metadataItem->comment = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
if (comment == NULL) {

Per SDRS, null isn't allowed, must use "" instead
strncpy(metadataItem->comment, "", MAX_STRING_LENGTH);

} else {

strncpy(metadataItem->comment, comment, MAX_STRING_LENGTH);

}

this is allocating a potentially huge block of data, when we really only need a
minimal chunk which can in principal be measured by strlen().

the more fundamental problem is that the code is not making use of the low-level
functionalities already in psLib: psStringCopy. here is how I would have done
this:

set metadata item comment
if (comment == NULL) {

Per SDRS, null isn't allowed, must use "" instead
metadataItem->comment = psStringCopy ("");

} else {

metadataItem->comment = psStringCopy (comment);

}

(now, even if we have a blanket policy that strings are always allocated in
large chunks, for efficiency's sake, we have isolated that policy decision to a
single function).

Change History (1)

comment:1 by robert.desonia@…, 21 years ago

Resolution: fixed
Status: newclosed

implemented fix as suggested.

Note: See TracTickets for help on using tickets.