summaryrefslogtreecommitdiff
path: root/library/DataDefs.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-04-20 13:04:03 +0400
committerAlexander Gavrilov2012-04-20 13:04:03 +0400
commitd95cc3435fe249e1c86e5af36b8a10e9009edd97 (patch)
treee20205016f43c95d15540e2ae49ba27efd3ce1c7 /library/DataDefs.cpp
parent0b32d374db8a58547d554d758e4e77ad850f54c5 (diff)
downloaddfhack-d95cc3435fe249e1c86e5af36b8a10e9009edd97.tar.gz
dfhack-d95cc3435fe249e1c86e5af36b8a10e9009edd97.tar.bz2
dfhack-d95cc3435fe249e1c86e5af36b8a10e9009edd97.tar.xz
Fix lua wrapper sizeof for static arrays.
Since it actually depends on the element type, it is more tricky.
Diffstat (limited to 'library/DataDefs.cpp')
-rw-r--r--library/DataDefs.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp
index 05988e41..06263518 100644
--- a/library/DataDefs.cpp
+++ b/library/DataDefs.cpp
@@ -42,13 +42,14 @@ using namespace DFHack;
void *type_identity::do_allocate_pod() {
- void *p = malloc(size);
- memset(p, 0, size);
+ size_t sz = byte_size();
+ void *p = malloc(sz);
+ memset(p, 0, sz);
return p;
}
void type_identity::do_copy_pod(void *tgt, const void *src) {
- memmove(tgt, src, size);
+ memmove(tgt, src, byte_size());
};
bool type_identity::do_destroy_pod(void *obj) {
@@ -81,8 +82,9 @@ bool type_identity::destroy(void *obj) {
}
void *enum_identity::do_allocate() {
- void *p = malloc(byte_size());
- memcpy(p, &first_item_value, std::min(byte_size(), sizeof(int64_t)));
+ size_t sz = byte_size();
+ void *p = malloc(sz);
+ memcpy(p, &first_item_value, std::min(sz, sizeof(int64_t)));
return p;
}