sprintf behaves strangely when given empty input cell
Muthiah Annamalai
muthuspost at gmail.com
Sat Jan 5 20:24:05 CST 2008
> Date: Sat, 05 Jan 2008 21:20:58 +0100
> From: Thomas Weber <thomas.weber.mail at gmail.com>
> Subject: sprintf behaves strangely when given empty input cell
> To: bug at octave.org
> Message-ID: <1199564459.32293.27.camel at localhost>
> Content-Type: text/plain
>
> Bug report for Octave 3.0.0 configured for i486-pc-linux-gnu
>
> Description:
> -----------
>
> copyfile(f1,...) fails when f1 is an empty cell. This is because sprintf
> seems to have a problem with empty cells as well:
>
> ====================================
> octave:1> f1 = {}
> f1 = {}(0x0)
> octave:2> sprintf ("\"%s\" ", f1)
> ans = ""
> octave:3> sprintf ("\"%s\" ", f1{:})
> ans = "
> ====================================
>
> Note that in the second sprintf() call, the second quote is missing.
>
From whatever I can tell, it seems the problem seems to start with the
parser.
Actually the call in sprintf() file-io.cc, os.printf() doesnt pass any
'args' the arguments
but the format to the printf is OK. Consequently the do_printf routine
breaks
as soon as a conversion ( '%s' ) doesnt have a matching argument, and
forgets
the rest of the formatted-list. I dont know whats the expected behavior,
and maybe
we can be forgiving and print the rest of the format-list. That way,
what Thomas
encoutered would atleast be > ans = "".
The larger question is what do we want to treat {:} for empty cells, and
I think
that is something JWE must address. Infact Octave behaves similarly even
if you
sprintf("\'%s\'",{}{:})
so one easy way to solve this is make the
octave_base_stream::do_printf() forgiving
and continue with other elements of the format-list hoping they are not
conversions.
Also similar problems exist due because of the treatment / choices at
parsing stage.
-Muthu
More information about the Bug-octave
mailing list