From b81ac363fc520b09f1109a0c328bff8b53649601 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Fri, 6 Apr 2012 21:28:58 +0200 Subject: [PATCH] Write names with a small sanity check --- components/esm/esm_writer.cpp | 1 + components/esm/loadland.cpp | 2 +- components/esm/loadlocks.cpp | 6 +++--- components/esm/loadpgrd.cpp | 4 ++-- components/esm/loadscpt.cpp | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/esm/esm_writer.cpp b/components/esm/esm_writer.cpp index da040c664..b4690807c 100644 --- a/components/esm/esm_writer.cpp +++ b/components/esm/esm_writer.cpp @@ -17,6 +17,7 @@ void ESMWriter::writeHString(const std::string& data) void ESMWriter::writeName(const std::string& name) { + assert((name.size() == 4 && name.c_str()[3] != '\0') || (name.size() == 5 && name.c_str()[4] == '\0')); write(name.c_str(), name.size()-1); } diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 4d3a4a0ed..9aa02e478 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -84,7 +84,7 @@ void Land::load(ESMReader &esm) void Land::save(ESMWriter &esm) { - esm.writeHString("INTV"); + esm.writeName("INTV"); esm.writeT(X); esm.writeT(Y); diff --git a/components/esm/loadlocks.cpp b/components/esm/loadlocks.cpp index ff01aac37..f49de1bc8 100644 --- a/components/esm/loadlocks.cpp +++ b/components/esm/loadlocks.cpp @@ -38,9 +38,9 @@ void Tool::save(ESMWriter &esm) switch(type) { - case Type_Repair: esm.writeHString("RIDT"); break; - case Type_Pick: esm.writeHString("LKDT"); break; - case Type_Probe: esm.writeHString("PBDT"); break; + case Type_Repair: esm.writeName("RIDT"); break; + case Type_Pick: esm.writeName("LKDT"); break; + case Type_Probe: esm.writeName("PBDT"); break; } esm.writeT(data, 16); diff --git a/components/esm/loadpgrd.cpp b/components/esm/loadpgrd.cpp index 572378dad..41dd34174 100644 --- a/components/esm/loadpgrd.cpp +++ b/components/esm/loadpgrd.cpp @@ -74,7 +74,7 @@ void Pathgrid::save(ESMWriter &esm) if (!points.empty()) { - esm.writeHString("PGRP"); + esm.writeName("PGRP"); for (PointList::iterator it = points.begin(); it != points.end(); ++it) { esm.writeT(*it); @@ -83,7 +83,7 @@ void Pathgrid::save(ESMWriter &esm) if (!edges.empty()) { - esm.writeHString("PGRC"); + esm.writeName("PGRC"); for (std::vector::iterator it = edges.begin(); it != edges.end(); ++it) { esm.writeT(it->v1); diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index 86d1d8e29..291259bc0 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -44,7 +44,7 @@ void Script::save(ESMWriter &esm) if (!varNames.empty()) { - esm.writeHString("SCVR"); + esm.writeName("SCVR"); for (std::vector::iterator it = varNames.begin(); it != varNames.end(); ++it) { esm.writeT(it->c_str(), it->size());