mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-29 22:49:41 +03:00 
			
		
		
		
	Backpatch variable renaming in formatting.c
Backpatch a9c22d1480 to make future
backpatching easier.
Backpatch through 9.0
			
			
This commit is contained in:
		| @@ -922,7 +922,7 @@ typedef struct NUMProc | |||||||
| 				num_count,		/* number of write digits	*/ | 				num_count,		/* number of write digits	*/ | ||||||
| 				num_in,			/* is inside number		*/ | 				num_in,			/* is inside number		*/ | ||||||
| 				num_curr,		/* current position in number	*/ | 				num_curr,		/* current position in number	*/ | ||||||
| 				num_pre,		/* space before first number	*/ | 				out_pre_spaces,	/* spaces before first digit	*/ | ||||||
|  |  | ||||||
| 				read_dec,		/* to_number - was read dec. point	*/ | 				read_dec,		/* to_number - was read dec. point	*/ | ||||||
| 				read_post,		/* to_number - number of dec. digit */ | 				read_post,		/* to_number - number of dec. digit */ | ||||||
| @@ -980,10 +980,11 @@ static FormatNode *NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *should | |||||||
| static char *int_to_roman(int number); | static char *int_to_roman(int number); | ||||||
| static void NUM_prepare_locale(NUMProc *Np); | static void NUM_prepare_locale(NUMProc *Np); | ||||||
| static char *get_last_relevant_decnum(char *num); | static char *get_last_relevant_decnum(char *num); | ||||||
| static void NUM_numpart_from_char(NUMProc *Np, int id, int plen); | static void NUM_numpart_from_char(NUMProc *Np, int id, int input_len); | ||||||
| static void NUM_numpart_to_char(NUMProc *Np, int id); | static void NUM_numpart_to_char(NUMProc *Np, int id); | ||||||
| static char *NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, | static char *NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, | ||||||
| 			  int plen, int sign, bool is_to_char, Oid collid); | 			  char *number, int from_char_input_len, int to_char_out_pre_spaces, | ||||||
|  | 			  int sign, bool is_to_char, Oid collid); | ||||||
| static DCHCacheEntry *DCH_cache_search(char *str); | static DCHCacheEntry *DCH_cache_search(char *str); | ||||||
| static DCHCacheEntry *DCH_cache_getnew(char *str); | static DCHCacheEntry *DCH_cache_getnew(char *str); | ||||||
|  |  | ||||||
| @@ -4042,7 +4043,7 @@ get_last_relevant_decnum(char *num) | |||||||
|  * ---------- |  * ---------- | ||||||
|  */ |  */ | ||||||
| static void | static void | ||||||
| NUM_numpart_from_char(NUMProc *Np, int id, int plen) | NUM_numpart_from_char(NUMProc *Np, int id, int input_len) | ||||||
| { | { | ||||||
| 	bool		isread = FALSE; | 	bool		isread = FALSE; | ||||||
|  |  | ||||||
| @@ -4054,8 +4055,8 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen) | |||||||
| 	if (*Np->inout_p == ' ') | 	if (*Np->inout_p == ' ') | ||||||
| 		Np->inout_p++; | 		Np->inout_p++; | ||||||
|  |  | ||||||
| #define OVERLOAD_TEST	(Np->inout_p >= Np->inout + plen) | #define OVERLOAD_TEST	(Np->inout_p >= Np->inout + input_len) | ||||||
| #define AMOUNT_TEST(_s) (plen-(Np->inout_p-Np->inout) >= _s) | #define AMOUNT_TEST(_s) (input_len-(Np->inout_p-Np->inout) >= _s) | ||||||
|  |  | ||||||
| 	if (*Np->inout_p == ' ') | 	if (*Np->inout_p == ' ') | ||||||
| 		Np->inout_p++; | 		Np->inout_p++; | ||||||
| @@ -4194,7 +4195,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen) | |||||||
| 		 * next char is not digit | 		 * next char is not digit | ||||||
| 		 */ | 		 */ | ||||||
| 		if (IS_LSIGN(Np->Num) && isread && | 		if (IS_LSIGN(Np->Num) && isread && | ||||||
| 			(Np->inout_p + 1) <= Np->inout + plen && | 			(Np->inout_p + 1) <= Np->inout + input_len && | ||||||
| 			!isdigit((unsigned char) *(Np->inout_p + 1))) | 			!isdigit((unsigned char) *(Np->inout_p + 1))) | ||||||
| 		{ | 		{ | ||||||
| 			int			x; | 			int			x; | ||||||
| @@ -4289,7 +4290,7 @@ NUM_numpart_to_char(NUMProc *Np, int id) | |||||||
| 	 * handle "9.9" --> " .1" | 	 * handle "9.9" --> " .1" | ||||||
| 	 */ | 	 */ | ||||||
| 	if (Np->sign_wrote == FALSE && | 	if (Np->sign_wrote == FALSE && | ||||||
| 		(Np->num_curr >= Np->num_pre || (IS_ZERO(Np->Num) && Np->Num->zero_start == Np->num_curr)) && | 		(Np->num_curr >= Np->out_pre_spaces || (IS_ZERO(Np->Num) && Np->Num->zero_start == Np->num_curr)) && | ||||||
| 		(IS_PREDEC_SPACE(Np) == FALSE || (Np->last_relevant && *Np->last_relevant == '.'))) | 		(IS_PREDEC_SPACE(Np) == FALSE || (Np->last_relevant && *Np->last_relevant == '.'))) | ||||||
| 	{ | 	{ | ||||||
| 		if (IS_LSIGN(Np->Num)) | 		if (IS_LSIGN(Np->Num)) | ||||||
| @@ -4333,7 +4334,7 @@ NUM_numpart_to_char(NUMProc *Np, int id) | |||||||
| 	 */ | 	 */ | ||||||
| 	if (id == NUM_9 || id == NUM_0 || id == NUM_D || id == NUM_DEC) | 	if (id == NUM_9 || id == NUM_0 || id == NUM_D || id == NUM_DEC) | ||||||
| 	{ | 	{ | ||||||
| 		if (Np->num_curr < Np->num_pre && | 		if (Np->num_curr < Np->out_pre_spaces && | ||||||
| 			(Np->Num->zero_start > Np->num_curr || !IS_ZERO(Np->Num))) | 			(Np->Num->zero_start > Np->num_curr || !IS_ZERO(Np->Num))) | ||||||
| 		{ | 		{ | ||||||
| 			/* | 			/* | ||||||
| @@ -4346,7 +4347,7 @@ NUM_numpart_to_char(NUMProc *Np, int id) | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		else if (IS_ZERO(Np->Num) && | 		else if (IS_ZERO(Np->Num) && | ||||||
| 				 Np->num_curr < Np->num_pre && | 				 Np->num_curr < Np->out_pre_spaces && | ||||||
| 				 Np->Num->zero_start <= Np->num_curr) | 				 Np->Num->zero_start <= Np->num_curr) | ||||||
| 		{ | 		{ | ||||||
| 			/* | 			/* | ||||||
| @@ -4418,7 +4419,7 @@ NUM_numpart_to_char(NUMProc *Np, int id) | |||||||
| 			++Np->number_p; | 			++Np->number_p; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		end = Np->num_count + (Np->num_pre ? 1 : 0) + (IS_DECIMAL(Np->Num) ? 1 : 0); | 		end = Np->num_count + (Np->out_pre_spaces ? 1 : 0) + (IS_DECIMAL(Np->Num) ? 1 : 0); | ||||||
|  |  | ||||||
| 		if (Np->last_relevant && Np->last_relevant == Np->number_p) | 		if (Np->last_relevant && Np->last_relevant == Np->number_p) | ||||||
| 			end = Np->num_curr; | 			end = Np->num_curr; | ||||||
| @@ -4444,13 +4445,10 @@ NUM_numpart_to_char(NUMProc *Np, int id) | |||||||
| 	++Np->num_curr; | 	++Np->num_curr; | ||||||
| } | } | ||||||
|  |  | ||||||
| /* |  | ||||||
|  * Note: 'plen' is used in FROM_CHAR conversion and it's length of |  | ||||||
|  * input (inout). In TO_CHAR conversion it's space before first number. |  | ||||||
|  */ |  | ||||||
| static char * | static char * | ||||||
| NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, | NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, | ||||||
| 			  int plen, int sign, bool is_to_char, Oid collid) | 			  char *number, int from_char_input_len, int to_char_out_pre_spaces, | ||||||
|  | 			  int sign, bool is_to_char, Oid collid) | ||||||
| { | { | ||||||
| 	FormatNode *n; | 	FormatNode *n; | ||||||
| 	NUMProc		_Np, | 	NUMProc		_Np, | ||||||
| @@ -4490,7 +4488,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, | |||||||
| 					 errmsg("\"RN\" not supported for input"))); | 					 errmsg("\"RN\" not supported for input"))); | ||||||
|  |  | ||||||
| 		Np->Num->lsign = Np->Num->pre_lsign_num = Np->Num->post = | 		Np->Num->lsign = Np->Num->pre_lsign_num = Np->Num->post = | ||||||
| 			Np->Num->pre = Np->num_pre = Np->sign = 0; | 			Np->Num->pre = Np->out_pre_spaces = Np->sign = 0; | ||||||
|  |  | ||||||
| 		if (IS_FILLMODE(Np->Num)) | 		if (IS_FILLMODE(Np->Num)) | ||||||
| 		{ | 		{ | ||||||
| @@ -4548,7 +4546,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, | |||||||
|  |  | ||||||
| 	if (is_to_char) | 	if (is_to_char) | ||||||
| 	{ | 	{ | ||||||
| 		Np->num_pre = plen; | 		Np->out_pre_spaces = to_char_out_pre_spaces; | ||||||
|  |  | ||||||
| 		if (IS_FILLMODE(Np->Num) && IS_DECIMAL(Np->Num)) | 		if (IS_FILLMODE(Np->Num) && IS_DECIMAL(Np->Num)) | ||||||
| 		{ | 		{ | ||||||
| @@ -4558,22 +4556,22 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, | |||||||
| 			 * If any '0' specifiers are present, make sure we don't strip | 			 * If any '0' specifiers are present, make sure we don't strip | ||||||
| 			 * those digits. | 			 * those digits. | ||||||
| 			 */ | 			 */ | ||||||
| 			if (Np->last_relevant && Np->Num->zero_end > Np->num_pre) | 			if (Np->last_relevant && Np->Num->zero_end > Np->out_pre_spaces) | ||||||
| 			{ | 			{ | ||||||
| 				char	   *last_zero; | 				char	   *last_zero; | ||||||
|  |  | ||||||
| 				last_zero = Np->number + (Np->Num->zero_end - Np->num_pre); | 				last_zero = Np->number + (Np->Num->zero_end - Np->out_pre_spaces); | ||||||
| 				if (Np->last_relevant < last_zero) | 				if (Np->last_relevant < last_zero) | ||||||
| 					Np->last_relevant = last_zero; | 					Np->last_relevant = last_zero; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (Np->sign_wrote == FALSE && Np->num_pre == 0) | 		if (Np->sign_wrote == FALSE && Np->out_pre_spaces == 0) | ||||||
| 			++Np->num_count; | 			++Np->num_count; | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		Np->num_pre = 0; | 		Np->out_pre_spaces = 0; | ||||||
| 		*Np->number = ' ';		/* sign space */ | 		*Np->number = ' ';		/* sign space */ | ||||||
| 		*(Np->number + 1) = '\0'; | 		*(Np->number + 1) = '\0'; | ||||||
| 	} | 	} | ||||||
| @@ -4589,7 +4587,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, | |||||||
| 		 Np->Num->pre, | 		 Np->Num->pre, | ||||||
| 		 Np->Num->post, | 		 Np->Num->post, | ||||||
| 		 Np->num_count, | 		 Np->num_count, | ||||||
| 		 Np->num_pre, | 		 Np->out_pre_spaces, | ||||||
| 		 Np->sign_wrote ? "Yes" : "No", | 		 Np->sign_wrote ? "Yes" : "No", | ||||||
| 		 IS_ZERO(Np->Num) ? "Yes" : "No", | 		 IS_ZERO(Np->Num) ? "Yes" : "No", | ||||||
| 		 Np->Num->zero_start, | 		 Np->Num->zero_start, | ||||||
| @@ -4624,7 +4622,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, | |||||||
| 			/* | 			/* | ||||||
| 			 * Check non-string inout end | 			 * Check non-string inout end | ||||||
| 			 */ | 			 */ | ||||||
| 			if (Np->inout_p >= Np->inout + plen) | 			if (Np->inout_p >= Np->inout + from_char_input_len) | ||||||
| 				break; | 				break; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -4654,7 +4652,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, | |||||||
| 					} | 					} | ||||||
| 					else | 					else | ||||||
| 					{ | 					{ | ||||||
| 						NUM_numpart_from_char(Np, n->key->id, plen); | 						NUM_numpart_from_char(Np, n->key->id, from_char_input_len); | ||||||
| 						break;	/* switch() case: */ | 						break;	/* switch() case: */ | ||||||
| 					} | 					} | ||||||
|  |  | ||||||
| @@ -4877,7 +4875,7 @@ do { \ | |||||||
|  */ |  */ | ||||||
| #define NUM_TOCHAR_finish \ | #define NUM_TOCHAR_finish \ | ||||||
| do { \ | do { \ | ||||||
| 	NUM_processor(format, &Num, VARDATA(result), numstr, plen, sign, true, PG_GET_COLLATION()); \ | 	NUM_processor(format, &Num, VARDATA(result), numstr, 0, out_pre_spaces, sign, true, PG_GET_COLLATION()); \ | ||||||
| 									\ | 									\ | ||||||
| 	if (shouldFree)					\ | 	if (shouldFree)					\ | ||||||
| 		pfree(format);				\ | 		pfree(format);				\ | ||||||
| @@ -4919,7 +4917,7 @@ numeric_to_number(PG_FUNCTION_ARGS) | |||||||
| 	numstr = (char *) palloc((len * NUM_MAX_ITEM_SIZ) + 1); | 	numstr = (char *) palloc((len * NUM_MAX_ITEM_SIZ) + 1); | ||||||
|  |  | ||||||
| 	NUM_processor(format, &Num, VARDATA(value), numstr, | 	NUM_processor(format, &Num, VARDATA(value), numstr, | ||||||
| 				  VARSIZE(value) - VARHDRSZ, 0, false, PG_GET_COLLATION()); | 				  VARSIZE(value) - VARHDRSZ, 0, 0, false, PG_GET_COLLATION()); | ||||||
|  |  | ||||||
| 	scale = Num.post; | 	scale = Num.post; | ||||||
| 	precision = Max(0, Num.pre) + scale; | 	precision = Max(0, Num.pre) + scale; | ||||||
| @@ -4949,7 +4947,7 @@ numeric_to_char(PG_FUNCTION_ARGS) | |||||||
| 	text	   *result; | 	text	   *result; | ||||||
| 	bool		shouldFree; | 	bool		shouldFree; | ||||||
| 	int			len = 0, | 	int			len = 0, | ||||||
| 				plen = 0, | 				out_pre_spaces = 0, | ||||||
| 				sign = 0; | 				sign = 0; | ||||||
| 	char	   *numstr, | 	char	   *numstr, | ||||||
| 			   *orgnum, | 			   *orgnum, | ||||||
| @@ -5005,6 +5003,7 @@ numeric_to_char(PG_FUNCTION_ARGS) | |||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|  | 		int			numstr_pre_len; | ||||||
| 		Numeric		val = value; | 		Numeric		val = value; | ||||||
|  |  | ||||||
| 		if (IS_MULTI(&Num)) | 		if (IS_MULTI(&Num)) | ||||||
| @@ -5039,14 +5038,17 @@ numeric_to_char(PG_FUNCTION_ARGS) | |||||||
| 			sign = '+'; | 			sign = '+'; | ||||||
| 			numstr = orgnum; | 			numstr = orgnum; | ||||||
| 		} | 		} | ||||||
| 		if ((p = strchr(numstr, '.'))) |  | ||||||
| 			len = p - numstr; |  | ||||||
| 		else |  | ||||||
| 			len = strlen(numstr); |  | ||||||
|  |  | ||||||
| 		if (Num.pre > len) | 		if ((p = strchr(numstr, '.'))) | ||||||
| 			plen = Num.pre - len; | 			numstr_pre_len = p - numstr; | ||||||
| 		else if (len > Num.pre) | 		else | ||||||
|  | 			numstr_pre_len = strlen(numstr); | ||||||
|  |  | ||||||
|  | 		/* needs padding? */ | ||||||
|  | 		if (numstr_pre_len < Num.pre) | ||||||
|  | 			out_pre_spaces = Num.pre - numstr_pre_len; | ||||||
|  | 		/* overflowed prefix digit format? */ | ||||||
|  | 		else if (numstr_pre_len > Num.pre) | ||||||
| 		{ | 		{ | ||||||
| 			numstr = (char *) palloc(Num.pre + Num.post + 2); | 			numstr = (char *) palloc(Num.pre + Num.post + 2); | ||||||
| 			fill_str(numstr, '#', Num.pre + Num.post + 1); | 			fill_str(numstr, '#', Num.pre + Num.post + 1); | ||||||
| @@ -5072,7 +5074,7 @@ int4_to_char(PG_FUNCTION_ARGS) | |||||||
| 	text	   *result; | 	text	   *result; | ||||||
| 	bool		shouldFree; | 	bool		shouldFree; | ||||||
| 	int			len = 0, | 	int			len = 0, | ||||||
| 				plen = 0, | 				out_pre_spaces = 0, | ||||||
| 				sign = 0; | 				sign = 0; | ||||||
| 	char	   *numstr, | 	char	   *numstr, | ||||||
| 			   *orgnum; | 			   *orgnum; | ||||||
| @@ -5103,6 +5105,8 @@ int4_to_char(PG_FUNCTION_ARGS) | |||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|  | 		int			numstr_pre_len; | ||||||
|  |  | ||||||
| 		if (IS_MULTI(&Num)) | 		if (IS_MULTI(&Num)) | ||||||
| 		{ | 		{ | ||||||
| 			orgnum = DatumGetCString(DirectFunctionCall1(int4out, | 			orgnum = DatumGetCString(DirectFunctionCall1(int4out, | ||||||
| @@ -5122,22 +5126,26 @@ int4_to_char(PG_FUNCTION_ARGS) | |||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| 			sign = '+'; | 			sign = '+'; | ||||||
| 		len = strlen(orgnum); |  | ||||||
|  |  | ||||||
|  | 		numstr_pre_len = strlen(orgnum); | ||||||
|  |  | ||||||
|  | 		/* post-decimal digits?  Pad out with zeros. */ | ||||||
| 		if (Num.post) | 		if (Num.post) | ||||||
| 		{ | 		{ | ||||||
| 			numstr = (char *) palloc(len + Num.post + 2); | 			numstr = (char *) palloc(numstr_pre_len + Num.post + 2); | ||||||
| 			strcpy(numstr, orgnum); | 			strcpy(numstr, orgnum); | ||||||
| 			*(numstr + len) = '.'; | 			*(numstr + numstr_pre_len) = '.'; | ||||||
| 			memset(numstr + len + 1, '0', Num.post); | 			memset(numstr + numstr_pre_len + 1, '0', Num.post); | ||||||
| 			*(numstr + len + Num.post + 1) = '\0'; | 			*(numstr + numstr_pre_len + Num.post + 1) = '\0'; | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| 			numstr = orgnum; | 			numstr = orgnum; | ||||||
|  |  | ||||||
| 		if (Num.pre > len) | 		/* needs padding? */ | ||||||
| 			plen = Num.pre - len; | 		if (numstr_pre_len < Num.pre) | ||||||
| 		else if (len > Num.pre) | 			out_pre_spaces = Num.pre - numstr_pre_len; | ||||||
|  | 		/* overflowed prefix digit format? */ | ||||||
|  | 		else if (numstr_pre_len > Num.pre) | ||||||
| 		{ | 		{ | ||||||
| 			numstr = (char *) palloc(Num.pre + Num.post + 2); | 			numstr = (char *) palloc(Num.pre + Num.post + 2); | ||||||
| 			fill_str(numstr, '#', Num.pre + Num.post + 1); | 			fill_str(numstr, '#', Num.pre + Num.post + 1); | ||||||
| @@ -5163,7 +5171,7 @@ int8_to_char(PG_FUNCTION_ARGS) | |||||||
| 	text	   *result; | 	text	   *result; | ||||||
| 	bool		shouldFree; | 	bool		shouldFree; | ||||||
| 	int			len = 0, | 	int			len = 0, | ||||||
| 				plen = 0, | 				out_pre_spaces = 0, | ||||||
| 				sign = 0; | 				sign = 0; | ||||||
| 	char	   *numstr, | 	char	   *numstr, | ||||||
| 			   *orgnum; | 			   *orgnum; | ||||||
| @@ -5208,6 +5216,8 @@ int8_to_char(PG_FUNCTION_ARGS) | |||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|  | 		int			numstr_pre_len; | ||||||
|  |  | ||||||
| 		if (IS_MULTI(&Num)) | 		if (IS_MULTI(&Num)) | ||||||
| 		{ | 		{ | ||||||
| 			double		multi = pow((double) 10, (double) Num.multi); | 			double		multi = pow((double) 10, (double) Num.multi); | ||||||
| @@ -5229,22 +5239,26 @@ int8_to_char(PG_FUNCTION_ARGS) | |||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| 			sign = '+'; | 			sign = '+'; | ||||||
| 		len = strlen(orgnum); |  | ||||||
|  |  | ||||||
|  | 		numstr_pre_len = strlen(orgnum); | ||||||
|  |  | ||||||
|  | 		/* post-decimal digits?  Pad out with zeros. */ | ||||||
| 		if (Num.post) | 		if (Num.post) | ||||||
| 		{ | 		{ | ||||||
| 			numstr = (char *) palloc(len + Num.post + 2); | 			numstr = (char *) palloc(numstr_pre_len + Num.post + 2); | ||||||
| 			strcpy(numstr, orgnum); | 			strcpy(numstr, orgnum); | ||||||
| 			*(numstr + len) = '.'; | 			*(numstr + numstr_pre_len) = '.'; | ||||||
| 			memset(numstr + len + 1, '0', Num.post); | 			memset(numstr + numstr_pre_len + 1, '0', Num.post); | ||||||
| 			*(numstr + len + Num.post + 1) = '\0'; | 			*(numstr + numstr_pre_len + Num.post + 1) = '\0'; | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| 			numstr = orgnum; | 			numstr = orgnum; | ||||||
|  |  | ||||||
| 		if (Num.pre > len) | 		/* needs padding? */ | ||||||
| 			plen = Num.pre - len; | 		if (numstr_pre_len < Num.pre) | ||||||
| 		else if (len > Num.pre) | 			out_pre_spaces = Num.pre - numstr_pre_len; | ||||||
|  | 		/* overflowed prefix digit format? */ | ||||||
|  | 		else if (numstr_pre_len > Num.pre) | ||||||
| 		{ | 		{ | ||||||
| 			numstr = (char *) palloc(Num.pre + Num.post + 2); | 			numstr = (char *) palloc(Num.pre + Num.post + 2); | ||||||
| 			fill_str(numstr, '#', Num.pre + Num.post + 1); | 			fill_str(numstr, '#', Num.pre + Num.post + 1); | ||||||
| @@ -5270,7 +5284,7 @@ float4_to_char(PG_FUNCTION_ARGS) | |||||||
| 	text	   *result; | 	text	   *result; | ||||||
| 	bool		shouldFree; | 	bool		shouldFree; | ||||||
| 	int			len = 0, | 	int			len = 0, | ||||||
| 				plen = 0, | 				out_pre_spaces = 0, | ||||||
| 				sign = 0; | 				sign = 0; | ||||||
| 	char	   *numstr, | 	char	   *numstr, | ||||||
| 			   *orgnum, | 			   *orgnum, | ||||||
| @@ -5310,6 +5324,7 @@ float4_to_char(PG_FUNCTION_ARGS) | |||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|  | 		int			numstr_pre_len; | ||||||
| 		float4		val = value; | 		float4		val = value; | ||||||
|  |  | ||||||
| 		if (IS_MULTI(&Num)) | 		if (IS_MULTI(&Num)) | ||||||
| @@ -5322,13 +5337,13 @@ float4_to_char(PG_FUNCTION_ARGS) | |||||||
|  |  | ||||||
| 		orgnum = (char *) palloc(MAXFLOATWIDTH + 1); | 		orgnum = (char *) palloc(MAXFLOATWIDTH + 1); | ||||||
| 		snprintf(orgnum, MAXFLOATWIDTH + 1, "%.0f", fabs(val)); | 		snprintf(orgnum, MAXFLOATWIDTH + 1, "%.0f", fabs(val)); | ||||||
| 		len = strlen(orgnum); | 		numstr_pre_len = strlen(orgnum); | ||||||
| 		if (Num.pre > len) |  | ||||||
| 			plen = Num.pre - len; | 		/* adjust post digits to fit max float digits */ | ||||||
| 		if (len >= FLT_DIG) | 		if (numstr_pre_len >= FLT_DIG) | ||||||
| 			Num.post = 0; | 			Num.post = 0; | ||||||
| 		else if (Num.post + len > FLT_DIG) | 		else if (numstr_pre_len + Num.post > FLT_DIG) | ||||||
| 			Num.post = FLT_DIG - len; | 			Num.post = FLT_DIG - numstr_pre_len; | ||||||
| 		snprintf(orgnum, MAXFLOATWIDTH + 1, "%.*f", Num.post, val); | 		snprintf(orgnum, MAXFLOATWIDTH + 1, "%.*f", Num.post, val); | ||||||
|  |  | ||||||
| 		if (*orgnum == '-') | 		if (*orgnum == '-') | ||||||
| @@ -5341,14 +5356,17 @@ float4_to_char(PG_FUNCTION_ARGS) | |||||||
| 			sign = '+'; | 			sign = '+'; | ||||||
| 			numstr = orgnum; | 			numstr = orgnum; | ||||||
| 		} | 		} | ||||||
| 		if ((p = strchr(numstr, '.'))) |  | ||||||
| 			len = p - numstr; |  | ||||||
| 		else |  | ||||||
| 			len = strlen(numstr); |  | ||||||
|  |  | ||||||
| 		if (Num.pre > len) | 		if ((p = strchr(numstr, '.'))) | ||||||
| 			plen = Num.pre - len; | 			numstr_pre_len = p - numstr; | ||||||
| 		else if (len > Num.pre) | 		else | ||||||
|  | 			numstr_pre_len = strlen(numstr); | ||||||
|  |  | ||||||
|  | 		/* needs padding? */ | ||||||
|  | 		if (numstr_pre_len < Num.pre) | ||||||
|  | 			out_pre_spaces = Num.pre - numstr_pre_len; | ||||||
|  | 		/* overflowed prefix digit format? */ | ||||||
|  | 		else if (numstr_pre_len > Num.pre) | ||||||
| 		{ | 		{ | ||||||
| 			numstr = (char *) palloc(Num.pre + Num.post + 2); | 			numstr = (char *) palloc(Num.pre + Num.post + 2); | ||||||
| 			fill_str(numstr, '#', Num.pre + Num.post + 1); | 			fill_str(numstr, '#', Num.pre + Num.post + 1); | ||||||
| @@ -5374,7 +5392,7 @@ float8_to_char(PG_FUNCTION_ARGS) | |||||||
| 	text	   *result; | 	text	   *result; | ||||||
| 	bool		shouldFree; | 	bool		shouldFree; | ||||||
| 	int			len = 0, | 	int			len = 0, | ||||||
| 				plen = 0, | 				out_pre_spaces = 0, | ||||||
| 				sign = 0; | 				sign = 0; | ||||||
| 	char	   *numstr, | 	char	   *numstr, | ||||||
| 			   *orgnum, | 			   *orgnum, | ||||||
| @@ -5414,6 +5432,7 @@ float8_to_char(PG_FUNCTION_ARGS) | |||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|  | 		int			numstr_pre_len; | ||||||
| 		float8		val = value; | 		float8		val = value; | ||||||
|  |  | ||||||
| 		if (IS_MULTI(&Num)) | 		if (IS_MULTI(&Num)) | ||||||
| @@ -5424,13 +5443,13 @@ float8_to_char(PG_FUNCTION_ARGS) | |||||||
| 			Num.pre += Num.multi; | 			Num.pre += Num.multi; | ||||||
| 		} | 		} | ||||||
| 		orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1); | 		orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1); | ||||||
| 		len = snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%.0f", fabs(val)); | 		numstr_pre_len = snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%.0f", fabs(val)); | ||||||
| 		if (Num.pre > len) |  | ||||||
| 			plen = Num.pre - len; | 		/* adjust post digits to fit max double digits */ | ||||||
| 		if (len >= DBL_DIG) | 		if (numstr_pre_len >= DBL_DIG) | ||||||
| 			Num.post = 0; | 			Num.post = 0; | ||||||
| 		else if (Num.post + len > DBL_DIG) | 		else if (numstr_pre_len + Num.post > DBL_DIG) | ||||||
| 			Num.post = DBL_DIG - len; | 			Num.post = DBL_DIG - numstr_pre_len; | ||||||
| 		snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%.*f", Num.post, val); | 		snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%.*f", Num.post, val); | ||||||
|  |  | ||||||
| 		if (*orgnum == '-') | 		if (*orgnum == '-') | ||||||
| @@ -5443,14 +5462,17 @@ float8_to_char(PG_FUNCTION_ARGS) | |||||||
| 			sign = '+'; | 			sign = '+'; | ||||||
| 			numstr = orgnum; | 			numstr = orgnum; | ||||||
| 		} | 		} | ||||||
| 		if ((p = strchr(numstr, '.'))) |  | ||||||
| 			len = p - numstr; |  | ||||||
| 		else |  | ||||||
| 			len = strlen(numstr); |  | ||||||
|  |  | ||||||
| 		if (Num.pre > len) | 		if ((p = strchr(numstr, '.'))) | ||||||
| 			plen = Num.pre - len; | 			numstr_pre_len = p - numstr; | ||||||
| 		else if (len > Num.pre) | 		else | ||||||
|  | 			numstr_pre_len = strlen(numstr); | ||||||
|  |  | ||||||
|  | 		/* needs padding? */ | ||||||
|  | 		if (numstr_pre_len < Num.pre) | ||||||
|  | 			out_pre_spaces = Num.pre - numstr_pre_len; | ||||||
|  | 		/* overflowed prefix digit format? */ | ||||||
|  | 		else if (numstr_pre_len > Num.pre) | ||||||
| 		{ | 		{ | ||||||
| 			numstr = (char *) palloc(Num.pre + Num.post + 2); | 			numstr = (char *) palloc(Num.pre + Num.post + 2); | ||||||
| 			fill_str(numstr, '#', Num.pre + Num.post + 1); | 			fill_str(numstr, '#', Num.pre + Num.post + 1); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user