From 53f169274aa006eb5165a236d2a99fa275c55c13 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Mon, 11 May 2015 15:51:21 +0200 Subject: [PATCH] fix end of string for the autogenerated embedded map config --- source/src/audiomanager.cpp | 1 - source/src/worldio.cpp | 18 +++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/source/src/audiomanager.cpp b/source/src/audiomanager.cpp index b910aa85..8555b9f3 100644 --- a/source/src/audiomanager.cpp +++ b/source/src/audiomanager.cpp @@ -850,7 +850,6 @@ void reloadmapsoundconfig() { vector sc; getcurrentmapconfig(sc, true); // only soundconfig - sc.add('\0'); execute(sc.getbuf()); // cheap and easy way ;) } diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 5eda2eef..adc1536c 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -320,7 +320,7 @@ void parseheaderextra(bool clearnonpersist = true, int ignoretypes = 0) // pars case HX_CONFIG: setcontext("map", "embedded"); - execute((const char *)q.buf); + execute((const char *)q.buf); // needs to have '\0' at the end resetcontext(); break; @@ -386,7 +386,7 @@ void extractconfigfile() stream *f = openfile(mcfname, "w"); if(f) { - f->write(headerextras[n]->data, headerextras[n]->len); + f->write(headerextras[n]->data, headerextras[n]->len > 0 ? headerextras[n]->len - 1 : 0); delete f; conoutf("extracted embedded map config to file %s", mcfname); deleteheaderextra(n); @@ -443,6 +443,7 @@ void getcurrentmapconfig(vector &f, bool onlysounds) cvecprintf(f, "mapsound \"%s\" %d\n", s.name, s.maxuses); } cvecprintf(f, "\n"); + f.add('\0'); } #ifdef _DEBUG @@ -451,7 +452,7 @@ COMMANDF(dumpmapconfig, "", () vector buf; getcurrentmapconfig(buf, false); stream *f = openfile("dumpmapconfig.txt", "w"); - if(f) f->write(buf.getbuf(), buf.length()); + if(f) f->write(buf.getbuf(), buf.length() - 1); DELETEP(f); hdr.flags |= MHF_AUTOMAPCONFIG; }); @@ -928,11 +929,7 @@ struct xmap memcpy(world, ::world, cubicsize * sizeof(sqr)); loopv(::ents) if(::ents[i].type != NOTUSED) ents.add() = ::ents[i]; copystring(mcfname, lastloadedconfigfile); // may have been "official" or not - if(hdr.flags & MHF_AUTOMAPCONFIG) - { - getcurrentmapconfig(mapconfig, false); - mapconfig.add('\0'); - } + if(hdr.flags & MHF_AUTOMAPCONFIG) getcurrentmapconfig(mapconfig, false); storeposition(position); vector tmp; // add undo/redo data in compressed form as temporary headerextra numundo = backupeditundo(tmp, MAXHEADEREXTRA, MAXHEADEREXTRA); @@ -1015,13 +1012,12 @@ struct xmap if(mapconfig.length()) { char *t = newstring(mapconfig.getbuf()), *p, *l = t; - do + while((p = strchr(l, '\n'))) { - if((p = strchr(l, '\n'))) *p = '\0'; + *p = '\0'; f->printf("restorexmap config %s\n", escapestring(l)); l = p + 1; } - while(p); delstring(t); } f->printf("restorexmap position %d %d %d %d %d // EOF, don't touch this\n\n", int(position[0]), int(position[1]), int(position[2]), int(position[3]), int(position[4]));