*fixed a string manipulation bug

This commit is contained in:
tony 2015-07-20 22:28:58 +08:00
parent b531e9b8f4
commit 013dbdb172
6 changed files with 14 additions and 7 deletions

View File

@ -1,3 +1,6 @@
Jul. 20 2015
Fixed a string manipulation bug
Jul. 12 2015 Jul. 12 2015
Added array manipulation functions Added array manipulation functions

Binary file not shown.

View File

@ -78,7 +78,7 @@ extern "C" {
/** Macros */ /** Macros */
#define _VER_MAJOR 1 #define _VER_MAJOR 1
#define _VER_MINOR 1 #define _VER_MINOR 1
#define _VER_REVISION 57 #define _VER_REVISION 58
#define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION)) #define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION))
/* Uncomment this line to treat warnings as error */ /* Uncomment this line to treat warnings as error */
@ -1747,10 +1747,11 @@ int _calc_expression(mb_interpreter_t* s, _ls_node_t** l, _object_t** val) {
} else { } else {
(*val)->type = c->type; (*val)->type = c->type;
if(_is_string(c)) { if(_is_string(c)) {
size_t _sl = strlen(_extract_string(c)); char* _str = _extract_string(c);
size_t _sl = strlen(_str);
(*val)->data.string = (char*)mb_malloc(_sl + 1); (*val)->data.string = (char*)mb_malloc(_sl + 1);
(*val)->data.string[_sl] = '\0'; (*val)->data.string[_sl] = '\0';
memcpy((*val)->data.string, c->data.string, _sl + 1); memcpy((*val)->data.string, _str, _sl + 1);
} else if(c->type == _DT_ARRAY) { } else if(c->type == _DT_ARRAY) {
(*val)->data = c->data; (*val)->data = c->data;
c->type = _DT_NIL; c->type = _DT_NIL;
@ -2722,6 +2723,9 @@ char* _extract_string(_object_t* obj) {
else if(obj->type == _DT_VAR && obj->data.variable->data->type == _DT_STRING) else if(obj->type == _DT_VAR && obj->data.variable->data->type == _DT_STRING)
result = obj->data.variable->data->data.string; result = obj->data.variable->data->data.string;
if(!result)
result = MB_NULL_STRING;
return result; return result;
} }

Binary file not shown.

Binary file not shown.

View File

@ -36,8 +36,8 @@
IDI_ICON_MAIN ICON "icon.ico" IDI_ICON_MAIN ICON "icon.ico"
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,1,57,0 FILEVERSION 1,1,58,0
PRODUCTVERSION 1,1,57,0 PRODUCTVERSION 1,1,58,0
FILEFLAGSMASK 0x17L FILEFLAGSMASK 0x17L
# ifdef _DEBUG # ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -55,13 +55,13 @@
VALUE "Comments", "MY-BASIC" VALUE "Comments", "MY-BASIC"
VALUE "CompanyName", "W. Renxin" VALUE "CompanyName", "W. Renxin"
VALUE "FileDescription", "MY-BASIC interpreter" VALUE "FileDescription", "MY-BASIC interpreter"
VALUE "FileVersion", "1, 1, 57, 0" VALUE "FileVersion", "1, 1, 58, 0"
VALUE "InternalName", "my_basic" VALUE "InternalName", "my_basic"
VALUE "LegalCopyright", "Copyright (C) 2011 - 2015 W. Renxin" VALUE "LegalCopyright", "Copyright (C) 2011 - 2015 W. Renxin"
VALUE "LegalTrademarks", "MY-BASIC" VALUE "LegalTrademarks", "MY-BASIC"
VALUE "OriginalFilename", "my_basic.exe" VALUE "OriginalFilename", "my_basic.exe"
VALUE "ProductName", "MY-BASIC" VALUE "ProductName", "MY-BASIC"
VALUE "ProductVersion", "1, 1, 57, 0" VALUE "ProductVersion", "1, 1, 58, 0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"