Skip to content

Commit

Permalink
rtlib: sanitize whitespace before change
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrm committed Dec 31, 2023
1 parent 0b38bc0 commit 31816d1
Showing 1 changed file with 62 additions and 62 deletions.
124 changes: 62 additions & 62 deletions src/rtlib/str_core.c
@@ -1,19 +1,19 @@
/* string/descriptor allocation, deletion, assignament, etc
*
* string is interpreted depending on the size argument passed:
* -1 = var-len
* 0 = fixed-len, size unknown (ie, returned from a non-FB function)
* >0 = fixed-len, size known (this size isn't used tho, as string will
* have garbage after the null-term, ie: spaces)
* destine string size can't be 0, as it is always known
*/
**
** string is interpreted depending on the size argument passed:
** -1 = var-len
** 0 = fixed-len, size unknown (ie, returned from a non-FB function)
** >0 = fixed-len, size known (this size isn't used tho, as string will
** have garbage after the null-term, ie: spaces)
** destine string size can't be 0, as it is always known
*/

#include "fb.h"
#include <stddef.h>

/**********
* temp string descriptors (string lock is assumed to be held in the thread-safe rlib version)
**********/
** temp string descriptors (string lock is assumed to be held in the thread-safe rlib version)
**********/

static FB_LIST tmpdsList = { 0, NULL, NULL, NULL };

Expand All @@ -25,7 +25,7 @@ FBCALL FBSTRING *fb_hStrAllocTmpDesc( void )

if( (tmpdsList.fhead == NULL) && (tmpdsList.head == NULL) )
fb_hListInit( &tmpdsList, fb_tmpdsTB,
sizeof(FB_STR_TMPDESC), FB_STR_TMPDESCRIPTORS );
sizeof(FB_STR_TMPDESC), FB_STR_TMPDESCRIPTORS );

dsc = (FB_STR_TMPDESC *)fb_hListAllocElem( &tmpdsList );
if( dsc == NULL )
Expand All @@ -51,21 +51,21 @@ static void fb_hStrFreeTmpDesc( FB_STR_TMPDESC *dsc )

FBCALL int fb_hStrDelTempDesc( FBSTRING *str )
{
FB_STR_TMPDESC *item =
(FB_STR_TMPDESC*) ( (char*)str - offsetof( FB_STR_TMPDESC, desc ) );
FB_STR_TMPDESC *item =
(FB_STR_TMPDESC*) ( (char*)str - offsetof( FB_STR_TMPDESC, desc ) );

/* is this really a temp descriptor? */
/* is this really a temp descriptor? */
if( (item < fb_tmpdsTB+0) ||
(item > fb_tmpdsTB+FB_STR_TMPDESCRIPTORS-1) )
(item > fb_tmpdsTB+FB_STR_TMPDESCRIPTORS-1) )
return -1;

fb_hStrFreeTmpDesc( item );
return 0;
}

/**********
* internal helper routines
**********/
** internal helper routines
**********/

/* alloc every 32-bytes */
#define hStrRoundSize( size ) (((size) + 31) & ~31)
Expand All @@ -80,8 +80,8 @@ FBCALL FBSTRING *fb_hStrAlloc( FBSTRING *str, ssize_t size )
{
str->data = (char *)malloc( size + 1 );
if( str->data == NULL )
{
str->len = str->size = 0;
{
str->len = str->size = 0;
return NULL;
}

Expand All @@ -91,7 +91,7 @@ FBCALL FBSTRING *fb_hStrAlloc( FBSTRING *str, ssize_t size )
str->size = newsize;
str->len = size;

return str;
return str;
}

FBCALL FBSTRING *fb_hStrRealloc( FBSTRING *str, ssize_t size, int preserve )
Expand All @@ -118,25 +118,25 @@ FBCALL FBSTRING *fb_hStrRealloc( FBSTRING *str, ssize_t size, int preserve )
}
else
{
char *pszOld = str->data;
char *pszOld = str->data;
str->data = (char *)realloc( pszOld, newsize + 1 );
/* failed? try the original request */
if( str->data == NULL )
{
str->data = (char *)realloc( pszOld, size + 1 );
newsize = size;
if( str->data == NULL )
{
/* restore the old memory block */
str->data = pszOld;
return NULL;
}
}
if( str->data == NULL )
{
/* restore the old memory block */
str->data = pszOld;
return NULL;
}
}
}

if( str->data == NULL )
{
str->len = str->size = 0;
{
str->len = str->size = 0;
return NULL;
}

Expand All @@ -145,43 +145,43 @@ FBCALL FBSTRING *fb_hStrRealloc( FBSTRING *str, ssize_t size, int preserve )

fb_hStrSetLength( str, size );

return str;
return str;
}

FBCALL FBSTRING *fb_hStrAllocTemp_NoLock( FBSTRING *str, ssize_t size )
{
int try_alloc = str==NULL;

if( try_alloc )
{
str = fb_hStrAllocTmpDesc( );
if( str==NULL )
return NULL;
}

if( fb_hStrRealloc( str, size, FB_FALSE ) == NULL )
{
if( try_alloc )
fb_hStrDelTempDesc( str );
return NULL;
}
else
str->len |= FB_TEMPSTRBIT;

return str;
if( try_alloc )
{
str = fb_hStrAllocTmpDesc( );
if( str==NULL )
return NULL;
}

if( fb_hStrRealloc( str, size, FB_FALSE ) == NULL )
{
if( try_alloc )
fb_hStrDelTempDesc( str );
return NULL;
}
else
str->len |= FB_TEMPSTRBIT;

return str;
}

FBCALL FBSTRING *fb_hStrAllocTemp( FBSTRING *str, ssize_t size )
{
FBSTRING *res;
FBSTRING *res;

FB_STRLOCK( );
FB_STRLOCK( );

res = fb_hStrAllocTemp_NoLock( str, size );
res = fb_hStrAllocTemp_NoLock( str, size );

FB_STRUNLOCK( );
FB_STRUNLOCK( );

return res;
return res;
}

FBCALL int fb_hStrDelTemp_NoLock( FBSTRING *str )
Expand All @@ -191,10 +191,10 @@ FBCALL int fb_hStrDelTemp_NoLock( FBSTRING *str )

/* is it really a temp? */
if( FB_ISTEMP( str ) )
fb_StrDelete( str );
fb_StrDelete( str );

/* del descriptor (must be done by last as it will be cleared) */
return fb_hStrDelTempDesc( str );
/* del descriptor (must be done by last as it will be cleared) */
return fb_hStrDelTempDesc( str );
}

FBCALL int fb_hStrDelTemp( FBSTRING *str )
Expand All @@ -212,11 +212,11 @@ FBCALL int fb_hStrDelTemp( FBSTRING *str )

FBCALL void fb_hStrCopy( char *dst, const char *src, ssize_t bytes )
{
if( (src != NULL) && (bytes > 0) )
{
dst = (char *) FB_MEMCPYX( dst, src, bytes );
}
if( (src != NULL) && (bytes > 0) )
{
dst = (char *) FB_MEMCPYX( dst, src, bytes );
}

/* add the null-term */
*dst = 0;
/* add the null-term */
*dst = 0;
}

0 comments on commit 31816d1

Please sign in to comment.