IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Opened 22 years ago

Closed 21 years ago

Last modified 21 years ago

#168 closed defect (fixed)

psMetadataItemPrint() doesn't perform specified conversions

Reported by: rhl@… Owned by: robert.desonia@…
Priority: normal Milestone:
Component: sys Version: unspecified
Severity: normal Keywords:
Cc:

Description


Change History (8)

comment:1 by rhl@…, 22 years ago

(I hit return too early).

The SDRS states that:

If the metadata item type is a numeric type, this formatting command must also be numeric,

and type conversion performed to the value to match the format type.

The code in rel2_2 simply takes the format and passes the correct member of the union; as I
read the SDRS, if the format is e.g. %g and the data type is S32, it's the responsibility of
psMetadataItemPrint() to convert the S32 to float before formatting it. I assume that all
conversions should be performed as if by assignment --- but maybe not (e.g. should
float -> int be rounded not truncated?)

comment:2 by robert.desonia@…, 22 years ago

Owner: changed from robert.desonia@… to calvin.harman@…

comment:3 by calvin.harman@…, 22 years ago

Since there are many % format specifiers in C and C99 the intent for this
function was for an implicit conversion to occur according to metadata item
type. As you've discovered, if the user inserts an incorrect % format
specifier, then he might have problems.

I'm not sure we if want to recreate our own % format parser, given that there
are many different format specifiers. Another problem is that that the user
could specify additional text with the % format specifier, just as we do with
printf statements. This would make parsing even more difficult.

If the SDRS were rewritten to specify which % format specifiers were allowed
for this function and no additional text is allowed, we might be able to
examine the format argument to see how to perform a conversion. How does that
sound?

comment:4 by eugene, 22 years ago

Status: newassigned

in such a case, it really is necessary to parse the format and cast
appropriately. Here is code I've used in the past to do this. (does not test
for the two-letter cases):

/* identify type (%NNNs %NNNNd %NNNNf) */

for (p1 = p2 + 1; (*p1 == '.')
(*p1 == '-') (*p1 == '+') (*p1 == '
')
isdigit(*p1); p1++);

memcpy (fmt, p2, p1 - p2 + 1);
switch (*p1) {

case 'e':
case 'f':

sprintf (tmp, fmt, atof(argv[i]));
break;

case 's':

sprintf (tmp, fmt, argv[i]);
break;

case 'd':
case 'c':
case 'x':

sprintf (tmp, fmt, atoi(argv[i]));
break;

default:

fprintf (stderr, "syntax error in format (only e,f,s,d,c,x allowed)\n");
return (FALSE);

}

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

Owner: changed from calvin.harman@… to robert.desonia@…
Status: assignednew

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

Status: newassigned

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

Resolution: fixed
Status: assignedclosed

I added a slightly more extensive version of your example code so as to handle
practically all of the C99 style formats.

comment:8 by Paul Price, 21 years ago

Tested S32 --> %f, which works.

Note: See TracTickets for help on using tickets.