]> git.draconx.ca Git - upkg.git/blobdiff - src/engine/music.gob
Stop using gnulib's flexmember module.
[upkg.git] / src / engine / music.gob
index 920e23c372854433af49a940c6e360b537092f15..e0d13b6e7428854d509947349633ed6070ef25e1 100644 (file)
@@ -1,23 +1,27 @@
 %alltop{
 /*
- *  upkg: tool for manipulating Unreal Tournament packages.
- *  Copyright © 2009-2011 Nick Bowler
+ * upkg: tool for manipulating Unreal Tournament packages.
+ * Copyright © 2009-2012, 2022 Nick Bowler
  *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 %}
 
+%ctop{
+#include <config.h>
+%}
+
 %{
 #include <stdio.h>
 #include <string.h>
@@ -39,10 +43,10 @@ class Engine:Music from U:Object (dynamic)
        private unsigned loaded = 0;
 
        interface U:Object:Loadable
-       private int load(G:Object *go)
+       private int load(U:Object *uo)
        {
-               struct upkg_file *f = U_OBJECT(go)->pkg_file;
-               Self *self = SELF(go);
+               struct upkg_file *f = uo->pkg_file;
+               Self *self = SELF(uo);
 
                if (!self->_priv->loaded) {
                        g_return_val_if_fail(f != NULL, -1);
@@ -60,9 +64,9 @@ class Engine:Music from U:Object (dynamic)
        }
 
        interface U:Object:Loadable
-       private void unload(G:Object *go)
+       private void unload(U:Object *uo)
        {
-               Self *self = SELF(go);
+               Self *self = SELF(uo);
 
                g_return_if_fail(self->_priv->loaded > 0);
 
@@ -71,45 +75,44 @@ class Engine:Music from U:Object (dynamic)
        }
 
        interface U:Object:Exportable
-       private int export(G:Object *go, FILE *f)
+       private int export(U:Object *uo, FILE *f)
        {
-               Self *self = SELF(go);
+               Self *self = SELF(uo);
                int rc;
 
-               if (self_load(go) != 0)
+               if (self_load(uo) != 0)
                        return -1;
 
                rc = music_mod_dump(self->_priv->mod, f);
 
-               self_unload(go);
+               self_unload(uo);
                return rc;
        }
 
        interface U:Object:Exportable
-       private int export_name(G:Object *go, char *buf, size_t n)
+       private int export_name(U:Object *uo, char *buf, size_t n)
        {
-               Self *self = SELF(go);
+               Self *self = SELF(uo);
                const char *type;
                int rc;
 
-               if (self_load(go) != 0) {
+               if (self_load(uo) != 0) {
                        if (n > 0)
                                buf[0] = '\0';
                        return 0;
                }
 
                type = music_mod_type(self->_priv->mod);
-               rc = snprintf(buf, n, "%s.%s", U_OBJECT(go)->pkg_file->name, type);
+               rc = snprintf(buf, n, "%s.%s", uo->pkg_file->name, type);
 
-               self_unload(go);
+               self_unload(uo);
                return rc;
        }
 
        override (U:Object) int deserialize(U:Object *uo)
        {
                struct upkg_file *f = uo->pkg_file;
-               Self *self = SELF(uo);
-               size_t rc, pos, buflen;
+               size_t rc, pos = 0, buflen;
                unsigned char buf[32];
                long size;
 
@@ -122,7 +125,7 @@ class Engine:Music from U:Object (dynamic)
                        return -1;
                pos += 1;
 
-               if (uo->pkg->version > 61) {
+               if (f->pkg->version > 61) {
                        /* Unknown field #2 */
                        if (buflen - pos < 4)
                                return -1;
@@ -130,7 +133,7 @@ class Engine:Music from U:Object (dynamic)
                }
 
                rc = upkg_decode_index(&size, buf+pos, buflen-pos);
-               if (rc == 0 || size < 0)
+               if (rc == 0 || size < 0 || size > f->len - pos)
                        return -1;
                pos += rc;