2011-03-01 02:06 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/utils/hbmk2/hbmk2.prg
  * harbour/config/dos/watcom.mk
  * harbour/config/win/watcom.mk
  * harbour/config/linux/watcom.mk
  * harbour/config/os2/watcom.mk
    ! fixed to not use -wcd124 and -wcd136 in OpenWatcom C++ builds

   * harbour/config/win/xcc.mk
     ! added -noexpobj as workaround for problems with creating
       shared library
     * removed now unnecessary $(RM) harbour*.dll

  * harbour/src/rtl/base64d.c
    * pacified warning
    % removed unnecessary condition with RTE - decoded string has to
      be shorter then the source one taken from HVM string item so for
      sure it cannot exceed maximum string item size

  * harbour/src/rtl/base64c.c
    * generate RTE if encode string size is too big 
    * eliminated unnecessary INT_MAX string limit
This commit is contained in:
Przemyslaw Czerpak
2011-03-01 01:07:16 +00:00
parent 7e41cd70bc
commit 701acbb116
9 changed files with 90 additions and 50 deletions

View File

@@ -51,49 +51,57 @@
*/
#include "hbapi.h"
#include "hbapierr.h"
HB_FUNC( HB_BASE64ENCODE )
{
HB_SIZE len = hb_parclen( 1 );
if( len <= INT_MAX ) /* TOFIX */
if( len > 0 )
{
const char * s = hb_parcx( 1 );
char * t, * p;
HB_SIZE dst = ( 4 * ( ( len + 2 ) / 3 ) + 1 ) * sizeof( char );
t = p = ( char * ) hb_xgrab( ( 4 * ( ( len + 2 ) / 3 ) + 1 ) * sizeof( *t ) );
while( len-- > 0 )
if( dst > len )
{
static const char s_b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int x, y;
const char * s = hb_parcx( 1 );
char * t, * p;
x = *s++;
*p++ = s_b64chars[ ( x >> 2 ) & 0x3F ];
t = p = ( char * ) hb_xgrab( dst );
if( len-- == 0 )
while( len-- > 0 )
{
*p++ = s_b64chars[ ( x << 4 ) & 0x3F ];
*p++ = '=';
*p++ = '=';
break;
}
y = *s++;
*p++ = s_b64chars[ ( ( x << 4 ) | ( ( y >> 4 ) & 0x0F ) ) & 0x3F ];
static const char s_b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int x, y;
if( len-- == 0 )
{
*p++ = s_b64chars[ ( y << 2 ) & 0x3F ];
*p++ = '=';
break;
x = *s++;
*p++ = s_b64chars[ ( x >> 2 ) & 0x3F ];
if( len-- == 0 )
{
*p++ = s_b64chars[ ( x << 4 ) & 0x3F ];
*p++ = '=';
*p++ = '=';
break;
}
y = *s++;
*p++ = s_b64chars[ ( ( x << 4 ) | ( ( y >> 4 ) & 0x0F ) ) & 0x3F ];
if( len-- == 0 )
{
*p++ = s_b64chars[ ( y << 2 ) & 0x3F ];
*p++ = '=';
break;
}
x = *s++;
*p++ = s_b64chars[ ( ( y << 2 ) | ( ( x >> 6 ) & 3 ) ) & 0x3F ];
*p++ = s_b64chars[ x & 0x3F ];
}
x = *s++;
*p++ = s_b64chars[ ( ( y << 2 ) | ( ( x >> 6 ) & 3 ) ) & 0x3F ];
*p++ = s_b64chars[ x & 0x3F ];
*p = '\0';
hb_retc_buffer( t );
}
*p = '\0';
hb_retc_buffer( t );
else
hb_errRT_BASE( EG_STROVERFLOW, 9999, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
else
hb_retc_null();

View File

@@ -54,11 +54,10 @@
*/
#include "hbapi.h"
#include "hbapierr.h"
/* Warning: this code works only on ASCII based machines */
static signed char base64_decode_value( char value_in )
static signed char base64_decode_value( int value_in )
{
static const signed char s_decoding[] =
{
@@ -69,10 +68,10 @@ static signed char base64_decode_value( char value_in )
};
value_in -= 43;
if( value_in < 0 || value_in >= ( char ) HB_SIZEOFARRAY( s_decoding ) )
if( value_in < 0 || value_in >= ( int ) HB_SIZEOFARRAY( s_decoding ) )
return -1;
return s_decoding[ ( int ) value_in ];
return s_decoding[ value_in ];
}
static HB_SIZE base64_decode_block( const char * code_in, const HB_SIZE length_in, char * pszPlainttextOut )
@@ -131,17 +130,10 @@ HB_FUNC( HB_BASE64DECODE )
if( nSrcLen > 0 )
{
HB_SIZE nDstLen = ( ( ( nSrcLen * 3 ) / 4 ) + 1 ) * sizeof( char );
char * code = ( char * ) hb_xgrab( nDstLen );
if( nDstLen <= HB_SIZE_MAX )
{
char * code = ( char * ) hb_xgrab( nDstLen );
nDstLen = base64_decode_block( hb_parcx( 1 ), nSrcLen, code );
hb_retclen_buffer( code, nDstLen );
}
else
hb_errRT_BASE( EG_STROVERFLOW, 9999, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
nDstLen = base64_decode_block( hb_parcx( 1 ), nSrcLen, code );
hb_retclen_buffer( code, nDstLen );
}
else
hb_retc_null();