Fixed build problem in C API. Beware of bad memory management!

develop
Petr Mrázek 2010-05-29 23:50:14 +02:00
parent fa0d881e16
commit 5ee4acfd2e
1 changed files with 6 additions and 3 deletions

@ -28,6 +28,8 @@ distribution.
extern "C" { extern "C" {
#endif #endif
//FIXME: beware of bad null-termination! I haven't tested anything here, but it seems that it could be corrupting or truncating strings.
char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObject* mats) char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObject* mats)
{ {
if(items != NULL && mats != NULL) if(items != NULL && mats != NULL)
@ -36,7 +38,8 @@ char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObje
if(desc.size() > 0) if(desc.size() > 0)
{ {
char* buf = (*alloc_char_buffer_callback)(desc.size()); char* buf;
(*alloc_char_buffer_callback)(buf,desc.size());
if(buf != NULL) if(buf != NULL)
{ {
@ -63,8 +66,8 @@ char* Items_getItemClass(DFHackObject* items, int32_t index)
if(iclass.size() > 0) if(iclass.size() > 0)
{ {
char* buf = (*alloc_char_buffer_callback)(iclass.size()); char* buf;
(*alloc_char_buffer_callback)(buf, iclass.size());
if(buf != NULL) if(buf != NULL)
{ {
size_t len = iclass.copy(buf, iclass.size()); size_t len = iclass.copy(buf, iclass.size());