sprintf behaves strangely when given empty input cell

John W. Eaton jwe at bevo.che.wisc.edu
Mon Jan 7 12:56:08 CST 2008


On  5-Jan-2008, Thomas Weber wrote:

| 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 = ""

Hmm, that looks like a possible bug, since I don't see how %s should
apply to a cell array (empty or not).  I made the change in the first
attachment to the cvs trunk.

| octave:3> sprintf ("\"%s\" ", f1{:})
| ans = "
| ====================================
| 
| Note that in the second sprintf() call, the second quote is missing.

This is not a bug.  The above call is equivalent to

  sprintf ("\"%s\"");

Since there are no arguments, the %s conversion does not happen, and
processing stops there.  This behavior is compatible with Matlab.

| Repeat-By:
| ---------
| 
| copyfile:
| octave:1> copyfile ({}, "/tmp/v")
| sh: -c: line 0: unexpected EOF while looking for matching `"'
| sh: -c: line 1: syntax error: unexpected end of file
| 
| sprintf:
| see above
| 
| Fix:
| ---
| 
| I don't have fix for sprintf, being an internal function. For
| copyfile(), the question if it should error out when there's no file to
| copy or silently ignore this.

How about the following patch to copyfile (and movefile)?  I applied
this to the cvs trunk and the 3.0 branch.

jwe


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: diffs-1
Url: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080107/5c9c62e8/attachment.ksh 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: diffs-2
Url: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080107/5c9c62e8/attachment-0001.ksh 


More information about the Bug-octave mailing list