X-Git-Url: http://git.subgeniuskitty.com/pforth/.git/blobdiff_plain/3760715f6e313ff90da32399fa1903c54f69d59b..e2531e837774276f6ffb3b284703c594644761f8:/csrc/pf_text.c diff --git a/csrc/pf_text.c b/csrc/pf_text.c index 9530546..6d36e2c 100644 --- a/csrc/pf_text.c +++ b/csrc/pf_text.c @@ -135,11 +135,16 @@ void pfReportThrow( ThrowCode code ) ** Copy a Forth String to a 'C' string. */ -char *ForthStringToC( char *dst, const char *FString ) +char *ForthStringToC( char *dst, const char *FString, cell_t dstSize ) { cell_t Len; Len = (cell_t) *FString; + /* Make sure the text + NUL can fit. */ + if( Len >= dstSize ) + { + Len = dstSize - 1; + } pfCopyMemory( dst, FString+1, Len ); dst[Len] = '\0'; @@ -149,17 +154,20 @@ char *ForthStringToC( char *dst, const char *FString ) /************************************************************** ** Copy a NUL terminated string to a Forth counted string. */ -char *CStringToForth( char *dst, const char *CString ) +char *CStringToForth( char *dst, const char *CString, cell_t dstSize ) { - char *s; cell_t i; - s = dst+1; - for( i=0; *CString; i++ ) + /* Make sure the SIZE+text can fit. */ + for( i=1; i