[xml] Bug in tree.c : xmlSaveFile, xmlSaveFileEnc

Date view Thread view Subject view Author view

From: Gary Pennington (Gary.Pennington@uk.sun.com)
Date: Tue Jan 16 2001 - 11:44:40 EST


Hi,

I'm using libxml2-2.2.11 and I've encountered what I think is a bug in
the two functions named.

In xmlDocDump, if an output buffer can't be created then -1 is returned
as per the documentation. However for both xmlSaveFile and
xmlSaveFileEnc, the return is 0 for the same condition. I think that
this should be changed so that it is -1 in all these cases if an output
buffer cannot be created.

I suppose that a return of 0 is kind of correct (since 0 bytes were
written) but it seems a little misleading to me since there has been an
error which isn't reported.

I encountered the problem when trying to save a file to a location in
which I didn't have permission to create files, so I think that
somewhere inside the guts of the IO mechanism an attempt to open a file
was rejected with EACCESS.

Patch is :-

calvin:libxml2-2.2.11:$ diff -c tree.c.ORIG tree.c
*** tree.c.ORIG Tue Jan 16 16:35:18 2001
--- tree.c Tue Jan 16 16:36:01 2001
***************
*** 5842,5848 ****
       * save the content to a temp buffer.
       */
      buf = xmlOutputBufferCreateFilename(filename, handler, 0);
! if (buf == NULL) return(0);

      xmlDocContentDumpOutput(buf, cur, encoding, 1);

--- 5842,5848 ----
       * save the content to a temp buffer.
       */
      buf = xmlOutputBufferCreateFilename(filename, handler, 0);
! if (buf == NULL) return(-1);

      xmlDocContentDumpOutput(buf, cur, encoding, 1);

***************
*** 5897,5903 ****
      }

      buf = xmlOutputBufferCreateFilename(filename, handler,
cur->compression);
! if (buf == NULL) return(0);

      xmlDocContentDumpOutput(buf, cur, NULL, 1);

--- 5897,5903 ----
      }

      buf = xmlOutputBufferCreateFilename(filename, handler,
cur->compression);
! if (buf == NULL) return(-1);

      xmlDocContentDumpOutput(buf, cur, NULL, 1);

calvin:libxml2-2.2.11:$

This is a trivial bug, but it annoyed me for a few minutes so I think
that the behaviour should be made consistent between these three
functions.

Gary

----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Tue Jan 16 2001 - 12:44:10 EST