diff options
| author | Alexander Gavrilov | 2012-09-01 11:25:24 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-09-01 11:25:24 +0400 |
| commit | e0097d8d43013d72d729e2ae71cdd6a73a110d8d (patch) | |
| tree | a03b0e71f2d9712d14193f26a0acd2bc3bc4470e /library | |
| parent | c68afdaad23ccb9e1c33ec118514c78e5376a72e (diff) | |
| download | dfhack-e0097d8d43013d72d729e2ae71cdd6a73a110d8d.tar.gz dfhack-e0097d8d43013d72d729e2ae71cdd6a73a110d8d.tar.bz2 dfhack-e0097d8d43013d72d729e2ae71cdd6a73a110d8d.tar.xz | |
Fix access to unnamed bits in bitfields, and allow hook.apply(false)
Diffstat (limited to 'library')
| -rw-r--r-- | library/DataDefs.cpp | 2 | ||||
| -rw-r--r-- | library/LuaTypes.cpp | 4 | ||||
| -rw-r--r-- | library/VTableInterpose.cpp | 8 | ||||
| -rw-r--r-- | library/include/VTableInterpose.h | 2 |
4 files changed, 11 insertions, 5 deletions
diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp index 34116444..fa2aacf7 100644 --- a/library/DataDefs.cpp +++ b/library/DataDefs.cpp @@ -374,7 +374,7 @@ void DFHack::bitfieldToString(std::vector<std::string> *pvec, const void *p, unsigned size, const bitfield_item_info *items) { for (unsigned i = 0; i < size; i++) { - int value = getBitfieldField(p, i, std::min(1,items[i].size)); + int value = getBitfieldField(p, i, std::max(1,items[i].size)); if (value) { std::string name = format_key(items[i].name, i); diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp index e7197796..9f2689fa 100644 --- a/library/LuaTypes.cpp +++ b/library/LuaTypes.cpp @@ -894,7 +894,7 @@ static int meta_bitfield_len(lua_State *state) static void read_bitfield(lua_State *state, uint8_t *ptr, bitfield_identity *id, int idx) { - int size = id->getBits()[idx].size; + int size = std::max(1, id->getBits()[idx].size); int value = getBitfieldField(ptr, idx, size); if (size <= 1) @@ -951,7 +951,7 @@ static int meta_bitfield_newindex(lua_State *state) } int idx = check_container_index(state, id->getNumBits(), 2, iidx, "write"); - int size = id->getBits()[idx].size; + int size = std::max(1, id->getBits()[idx].size); if (lua_isboolean(state, 3) || lua_isnil(state, 3)) setBitfieldField(ptr, idx, size, lua_toboolean(state, 3)); diff --git a/library/VTableInterpose.cpp b/library/VTableInterpose.cpp index 079890fe..583ef518 100644 --- a/library/VTableInterpose.cpp +++ b/library/VTableInterpose.cpp @@ -335,8 +335,14 @@ void VMethodInterposeLinkBase::on_host_delete(virtual_identity *from) } } -bool VMethodInterposeLinkBase::apply() +bool VMethodInterposeLinkBase::apply(bool enable) { + if (!enable) + { + remove(); + return true; + } + if (is_applied()) return true; if (!host->vtable_ptr) diff --git a/library/include/VTableInterpose.h b/library/include/VTableInterpose.h index c9482f82..7ba6b67a 100644 --- a/library/include/VTableInterpose.h +++ b/library/include/VTableInterpose.h @@ -159,7 +159,7 @@ namespace DFHack ~VMethodInterposeLinkBase(); bool is_applied() { return applied; } - bool apply(); + bool apply(bool enable = true); void remove(); }; |
