mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 17:23:04 +01:00
Fix bugs in ib_udf functions rtrim, ltrim and log. Found and fixed by Paul Vinkenoog
This commit is contained in:
parent
aa566d11b7
commit
8fb57b8f47
@ -146,7 +146,7 @@ double EXPORT IB_UDF_ln( double *a)
|
|||||||
|
|
||||||
double EXPORT IB_UDF_log( double *a, double *b)
|
double EXPORT IB_UDF_log( double *a, double *b)
|
||||||
{
|
{
|
||||||
return (log(*a) / log(*b));
|
return (log(*b) / log(*a));
|
||||||
}
|
}
|
||||||
|
|
||||||
double EXPORT IB_UDF_log10( double *a)
|
double EXPORT IB_UDF_log10( double *a)
|
||||||
@ -205,21 +205,14 @@ char *EXPORT IB_UDF_lpad( char *s, long *a, char *c)
|
|||||||
char *EXPORT IB_UDF_ltrim( char *s)
|
char *EXPORT IB_UDF_ltrim( char *s)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
char *p;
|
|
||||||
long length;
|
long length;
|
||||||
|
|
||||||
if ( (length = strlen(s)) ) {
|
|
||||||
while (*s == ' ') /* skip leading blanks */
|
while (*s == ' ') /* skip leading blanks */
|
||||||
s++;
|
s++;
|
||||||
|
|
||||||
length = strlen(s);
|
length = strlen(s);
|
||||||
buf = (char *) ib_util_malloc(length + 1);
|
buf = (char *) ib_util_malloc(length + 1);
|
||||||
memcpy(buf, s, length);
|
memcpy(buf, s, length);
|
||||||
p = buf + length;
|
buf[length] = '\0';
|
||||||
*p = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@ -281,22 +274,14 @@ char *EXPORT IB_UDF_rpad( char *s, long *a, char *c)
|
|||||||
char *EXPORT IB_UDF_rtrim( char *s)
|
char *EXPORT IB_UDF_rtrim( char *s)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
char *q;
|
|
||||||
char *buf;
|
char *buf;
|
||||||
long length;
|
long length;
|
||||||
|
|
||||||
if ( (length = strlen(s)) ) {
|
for (p = s + strlen(s); --p >= s && *p == ' ';);
|
||||||
p = s + length - 1;
|
|
||||||
while ((s != p) && (*p == ' '))
|
|
||||||
p--;
|
|
||||||
length = p - s + 1;
|
length = p - s + 1;
|
||||||
buf = (char *) ib_util_malloc(length + 1);
|
buf = (char *) ib_util_malloc(length + 1);
|
||||||
memcpy(buf, s, length);
|
memcpy(buf, s, length);
|
||||||
q = buf + length;
|
buf[length] = '\0';
|
||||||
*q = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user