Skip to content

Commit

Permalink
Merge pull request Meridian59#342 from skittles1/or_strsub
Browse files Browse the repository at this point in the history
Fix StringSubstitute errors.
  • Loading branch information
Meridian59 committed Jun 1, 2016
2 parents 4a167dd + 71078a2 commit ee9e80b
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions blakserv/ccode.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ int C_StringSubstitute(int object_id,local_var_type *local_vars,
// make a zero-terminated scratch copy of string1
len1 = snod1->len_data;
memcpy( buf1, snod1->data, len1 );
buf1[len1+1] = 0x0;
buf1[len1] = 0x0;
break;

case TAG_TEMP_STRING :
Expand All @@ -739,7 +739,7 @@ int C_StringSubstitute(int object_id,local_var_type *local_vars,
// make a zero-terminated scratch copy of string1
len1 = snod1->len_data;
memcpy( buf1, snod1->data, len1 );
buf1[len1+1] = 0x0;
buf1[len1] = 0x0;
break;

case TAG_RESOURCE :
Expand Down Expand Up @@ -806,7 +806,7 @@ int C_StringSubstitute(int object_id,local_var_type *local_vars,

// now make a zero-terminated scratch copy of string0
memcpy( s0, snod0->data, snod0->len_data );
s0[snod0->len_data+1] = 0x0;
s0[snod0->len_data] = 0x0;

// so we can use stristr to do the work
subspot = stristr( s0, s1 );
Expand All @@ -816,14 +816,6 @@ int C_StringSubstitute(int object_id,local_var_type *local_vars,

if( subspot != NULL ) // only substitute if string1 is found in string0
{
char* source;
int source_len;

source_len = snod0->len_data;
source = (char *)AllocateMemory(MALLOC_ID_STRING, source_len+1);
memcpy(source, snod0->data, source_len);
source[source_len] = '\0';

if (snod0 != GetTempString())
{
// free the old string0 and allocate a new (possibly longer) string0
Expand All @@ -845,8 +837,6 @@ int C_StringSubstitute(int object_id,local_var_type *local_vars,
snod0->len_data = new_len;
snod0->data[snod0->len_data] = '\0';

FreeMemory(MALLOC_ID_STRING,source,source_len+1);

r_val.v.data = 1;
}

Expand Down

0 comments on commit ee9e80b

Please sign in to comment.