X-Git-Url: http://git.subgeniuskitty.com/pforth/.git/blobdiff_plain/bb6b2dcdd9acffabfd373c4c3f6b64a9cc43f335..e2531e837774276f6ffb3b284703c594644761f8:/csrc/pf_text.c diff --git a/csrc/pf_text.c b/csrc/pf_text.c index ebf5c48..6d36e2c 100644 --- a/csrc/pf_text.c +++ b/csrc/pf_text.c @@ -82,6 +82,8 @@ void pfReportError( const char *FunctionName, Err ErrCode ) s = "endian-ness of dictionary does not match code"; break; case PF_ERR_FLOAT_CONFLICT & 0xFF: s = "float support mismatch between .dic file and code"; break; + case PF_ERR_CELL_SIZE_CONFLICT & 0xFF: + s = "cell size mismatch between .dic file and code"; break; default: s = "unrecognized error code!"; break; } @@ -133,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 ) { - int32 Len; + cell_t Len; - Len = (int32) *FString; + 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'; @@ -147,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; - int32 i; + cell_t i; - s = dst+1; - for( i=0; *CString; i++ ) + /* Make sure the SIZE+text can fit. */ + for( i=1; is2; */ -int32 ffCompare( const char *s1, int32 len1, const char *s2, int32 len2 ) +cell_t ffCompare( const char *s1, cell_t len1, const char *s2, int32_t len2 ) { - int32 i, result, n, diff; + cell_t i, result, n, diff; result = 0; n = MIN(len1,len2); @@ -243,15 +253,15 @@ int32 ffCompare( const char *s1, int32 len1, const char *s2, int32 len2 ) /*************************************************************** ** Convert number to text. */ -#define CNTT_PAD_SIZE ((sizeof(int32)*8)+2) /* PLB 19980522 - Expand PAD so "-1 binary .s" doesn't crash. */ +#define CNTT_PAD_SIZE ((sizeof(cell_t)*8)+2) /* PLB 19980522 - Expand PAD so "-1 binary .s" doesn't crash. */ static char cnttPad[CNTT_PAD_SIZE]; -char *ConvertNumberToText( int32 Num, int32 Base, int32 IfSigned, int32 MinChars ) +char *ConvertNumberToText( cell_t Num, cell_t Base, int32_t IfSigned, int32_t MinChars ) { - int32 IfNegative = 0; + cell_t IfNegative = 0; char *p,c; - uint32 NewNum, Rem, uNum; - int32 i = 0; + ucell_t NewNum, Rem, uNum; + cell_t i = 0; uNum = Num; if( IfSigned ) @@ -287,9 +297,9 @@ char *ConvertNumberToText( int32 Num, int32 Base, int32 IfSigned, int32 MinChars /*************************************************************** ** Diagnostic routine that prints memory in table format. */ -void DumpMemory( void *addr, int32 cnt) +void DumpMemory( void *addr, cell_t cnt) { - int32 ln, cn, nlines; + cell_t ln, cn, nlines; unsigned char *ptr, *cptr, c; nlines = (cnt + 15) / 16; @@ -300,12 +310,12 @@ void DumpMemory( void *addr, int32 cnt) for (ln=0; ln