* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
- * $Id: mbutils.c,v 1.15 2001/02/10 02:31:27 tgl Exp $
+ * $Id: mbutils.c,v 1.16 2001/03/08 00:24:34 tgl Exp $
*/
#include "postgres.h"
int len = 0;
int l;
- while (*mbstr && limit > 0)
+ while (limit > 0 && *mbstr)
{
l = pg_mblen(mbstr);
limit -= l;
int clen = 0;
int l;
- while (*mbstr && len > 0)
+ while (len > 0 && *mbstr)
{
l = pg_mblen(mbstr);
if ((clen + l) > limit)
}
/*
- * fuctions for utils/init
+ * functions for utils/init
*/
static int DatabaseEncoding = MULTIBYTE;
/*
* conversion functions between pg_wchar and multi-byte streams.
* Tatsuo Ishii
- * $Id: wchar.c,v 1.15 2001/02/11 01:59:22 ishii Exp $
+ * $Id: wchar.c,v 1.16 2001/03/08 00:24:34 tgl Exp $
*
* WIN1250 client encoding updated by Pavel Behal
*
{
int cnt = 0;
- while (*from && len > 0)
+ while (len > 0 && *from)
{
*to++ = *from++;
len--;
{
int cnt = 0;
- while (*from && len > 0)
+ while (len > 0 && *from)
{
- if (*from == SS2)
+ if (*from == SS2 && len >= 2)
{
from++;
- len--;
*to = 0xff & *from++;
- len--;
+ len -= 2;
}
- else if (*from == SS3)
+ else if (*from == SS3 && len >= 3)
{
from++;
*to = *from++ << 8;
*to |= 0x3f & *from++;
len -= 3;
}
- else if (*from & 0x80)
+ else if ((*from & 0x80) && len >= 2)
{
*to = *from++ << 8;
*to |= *from++;
{
int cnt = 0;
- while (*from && len > 0)
+ while (len > 0 && *from)
{
- if (*from == SS2)
+ if (*from == SS2 && len >= 3)
{
from++;
- len--;
*to = 0x3f00 & (*from++ << 8);
*to = *from++;
- len -= 2;
+ len -= 3;
}
- else if (*from == SS3)
+ else if (*from == SS3 && len >= 3)
{
from++;
*to = *from++ << 8;
*to |= 0x3f & *from++;
len -= 3;
}
- else if (*from & 0x80)
+ else if ((*from & 0x80) && len >= 2)
{
*to = *from++ << 8;
*to |= *from++;
{
int cnt = 0;
- while (*from && len > 0)
+ while (len > 0 && *from)
{
- if (*from == SS2)
+ if (*from == SS2 && len >= 4)
{
from++;
- len--;
*to = *from++ << 16;
*to |= *from++ << 8;
*to |= *from++;
- len -= 3;
+ len -= 4;
}
- else if (*from == SS3)
+ else if (*from == SS3 && len >= 3)
{
from++;
*to = *from++ << 8;
*to |= 0x3f & *from++;
len -= 3;
}
- else if (*from & 0x80)
+ else if ((*from & 0x80) && len >= 2)
{
*to = *from++ << 8;
*to |= *from++;
c3;
int cnt = 0;
- while (*from && len > 0)
+ while (len > 0 && *from)
{
if ((*from & 0x80) == 0)
{
*to = *from++;
len--;
}
- else if ((*from & 0xe0) == 0xc0)
+ else if ((*from & 0xe0) == 0xc0 && len >= 2)
{
c1 = *from++ & 0x1f;
c2 = *from++ & 0x3f;
- len -= 2;
*to = c1 << 6;
*to |= c2;
+ len -= 2;
}
- else if ((*from & 0xe0) == 0xe0)
+ else if ((*from & 0xe0) == 0xe0 && len >= 3)
{
c1 = *from++ & 0x0f;
c2 = *from++ & 0x3f;
c3 = *from++ & 0x3f;
- len -= 3;
*to = c1 << 12;
*to |= c2 << 6;
*to |= c3;
+ len -= 3;
}
else
{
{
int cnt = 0;
- while (*from && len > 0)
+ while (len > 0 && *from)
{
- if (IS_LC1(*from))
+ if (IS_LC1(*from) && len >= 2)
{
*to = *from++ << 16;
*to |= *from++;
len -= 2;
}
- else if (IS_LCPRV1(*from))
+ else if (IS_LCPRV1(*from) && len >= 3)
{
from++;
*to = *from++ << 16;
*to |= *from++;
len -= 3;
}
- else if (IS_LC2(*from))
+ else if (IS_LC2(*from) && len >= 3)
{
*to = *from++ << 16;
*to |= *from++ << 8;
*to |= *from++;
len -= 3;
}
- else if (IS_LCPRV2(*from))
+ else if (IS_LCPRV2(*from) && len >= 4)
{
from++;
*to = *from++ << 16;
{
int cnt = 0;
- while (*from && len-- > 0)
+ while (len > 0 && *from)
{
*to++ = *from++;
+ len--;
cnt++;
}
*to = 0;