src/gedlib/misc.c
/*===========================================
 * rmvat_char -- Remove bracketing characters
 *  from around a string
 *  returns static buffer
 *==========================================*/
- Remove bracketing characters
from around a string
returns static buffer
- Remove bracketing characters from around a string returns static buffer
static STRING
rmvat_char (CNSTRING str, char c, char d)
{
#define RMVAT_SIZE 32
	static char buffer[RMVAT_SIZE][32];
	static INT dex = 0;
	STRING p;
	int len;
	if((str == NULL) || (*str == '\0')) return(NULL);
	if (str[0] != c) return NULL;
	rmvat_count++;
	dex++;
	if (dex == RMVAT_SIZE) dex = 0;
	p = buffer[dex];
	len = strlen(str+1);
	if (str[len] != d) return NULL;
	if(len > 31) len = 31;		
	else if(len > 0) len--;
	strncpy(p, &str[1], len);
	p[len] = 0;	
	return p;
}
static STRING rmvat_char ( CNSTRING str , char c , char d ) { #define RMVAT_SIZE  32 static char buffer [ RMVAT_SIZE ] [ 32 ] ; static INT dex = 0 ; STRING p ; int len ; if ( ( str == NULL ) || ( * str == ' \0 ' ) ) return ( NULL ) ; if ( str [ 0 ] != c ) return NULL ; rmvat_count ++ ; dex ++ ; if ( dex == RMVAT_SIZE ) dex = 0 ; p = buffer [ dex ] ; len = strlen ( str + 1 ) ; if ( str [ len ] != d ) return NULL ; if ( len > 31 ) len = 31 ; else if ( len > 0 ) len -- ; strncpy ( p , & str [ 1 ] , len ) ; p [ len ] = 0 ; return p ; }
rmvat_char -- Remove bracketing characters
  from around a string
  returns static buffer
rmvat_char -- Remove bracketing characters from around a string returns static buffer
/*
	 * This static buffer is an array of buffers that can be used for
	 * addat'ed strings.  We need to use an array here since we may have
	 * multiple calls within a single operation and we don't want to
	 * overwrite values that haven't been copied or made permanent.
	 * Since GEDCOM 5.5 spefies that XREF values can be up to 22 chars,
	 * the static buffer needs to be at least 22+2+1=25 chars, but leave a
	 * little extra.
	 *
	 * Currently we need to support a large number of rmvat() calls.
	 *
	 * The current limit of 32 appears sufficient, but there may be cases
	 * where static buffer reuse causes data corruption of various types.
	 * The solutions are to a) ensure that the values returned by rmvat()
	 * are saved, or b) increase the buffer size.
	 *
	 * Refer to https://github.com/lifelines/lifelines/issues/439 for one
	 * such scenario; a single INDI with 32 ASSO tags caused the INDI key
	 * to become corrupted because the ASSO tag processing caused the rmvat
	 * buffer to wrap.
	 */ /* Watch out for bad pointers */ /* 31 characters is maximum */ /* overwrite trailing "@" with null */