[AD] dat/grabber and pack_fopen_chunk

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


As seen on https://www.allegro.cc/forums/thread/558565

  I found the bug, but I don't have time to fix it. If someone could fix
  it, that would be great.  Here is the problem: there is a call to
  pack_fopen_chunk() in datedit.c that fails.  Due to some sloppy
  coding, this was not checked.  pack_fopen_chunk() is implemented by
  opening a temporary file so even if you have write access to the
  target directory it could fail if you don't have write access to the
  directory for the temporary file (I think it is the current
  directory).  Someone needs to fix pack_fopen_chunk().

  In the meantime, I will apply a patch so at least dat and grabber will
  return a failure code rather than aborting.

The patch is attached.  Someone please adopt this bug.  Thanks.

Peter
--- tools/datedit.c	(revision 5720)
+++ tools/datedit.c	(local)
@@ -422,11 +422,15 @@ static int percent(int a, int b)
 
 
 /* saves an object */
-static int save_object(DATAFILE *dat, AL_CONST int *fixed_prop, int pack, int pack_kids, int strip, int sort, int verbose, PACKFILE *f)
+static int save_object(DATAFILE *dat, AL_CONST int *fixed_prop, int pack, int pack_kids,
+                       int strip, int sort, int verbose, AL_CONST PACKFILE *f)
 {
    int i, ret;
    DATAFILE_PROPERTY *prop;
    int (*save)(DATAFILE *, AL_CONST int *, int, int, int, int, int, int, PACKFILE *);
+   PACKFILE *fchunk;
+
+   ASSERT(f);
 
    prop = dat->prop;
    datedit_sort_properties(prop);
@@ -448,7 +452,10 @@ static int save_object(DATAFILE *dat, AL
       datedit_startmsg("%-28s", get_datafile_property(dat, DAT_NAME));
 
    pack_mputl(dat->type, f);
-   f = pack_fopen_chunk(f, ((!pack) && (pack_kids) && (dat->type != DAT_FILE)));
+   fchunk = pack_fopen_chunk(f, ((!pack) && (pack_kids) && (dat->type != DAT_FILE)));
+   if (!fchunk) {
+      return FALSE;
+   }
    file_datasize += 12;
 
    save = NULL;
@@ -467,15 +474,16 @@ static int save_object(DATAFILE *dat, AL
       if (verbose)
 	 datedit_endmsg("");
 
-      ret = save((DATAFILE *)dat->dat, fixed_prop, pack, pack_kids, strip, sort, verbose, FALSE, f);
+      ret = save((DATAFILE *)dat->dat, fixed_prop, pack, pack_kids, strip, sort, verbose, FALSE, fchunk);
 
       if (verbose)
 	 datedit_startmsg("End of %-21s", get_datafile_property(dat, DAT_NAME));
    }
    else
-      ret = save(dat, fixed_prop, (pack || pack_kids), FALSE, strip, sort, verbose, FALSE, f);
+      ret = save(dat, fixed_prop, (pack || pack_kids), FALSE, strip, sort, verbose, FALSE, fchunk);
 
-   pack_fclose_chunk(f);
+   pack_fclose_chunk(fchunk);
+   fchunk = NULL;
 
    if (verbose) {
       if ((!pack) && (pack_kids) && (dat->type != DAT_FILE)) {
@@ -502,6 +510,8 @@ static int save_datafile(DATAFILE *dat, 
 {
    int c, size;
 
+   ASSERT(f);
+
    if (sort)
       datedit_sort_datafile(dat);
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/