Corrected FONTCHARACTER utilities and e-activity warnings
This commit is contained in:
parent
a920161992
commit
4a7b1b1c47
|
@ -69,11 +69,11 @@ int g1m_fctomb(char *s, FONTCHARACTER fc)
|
|||
{
|
||||
/* no string? */
|
||||
if (!s)
|
||||
return (2);
|
||||
return (-1);
|
||||
|
||||
/* extended? */
|
||||
if (fc > 0xff) {
|
||||
*s++ = fc >> 8;
|
||||
*s++ = (fc >> 8) & 0xff;
|
||||
*s = fc & 0xff;
|
||||
return (2);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ size_t g1m_mbstofcs(FONTCHARACTER *dest, const char *src, size_t n)
|
|||
*
|
||||
* @arg dst the destination.
|
||||
* @arg src the source.
|
||||
* @arg n number of FONTCHARACTER elements in the source.
|
||||
* @arg n the size of the source.
|
||||
* @return the size of the destination.
|
||||
*/
|
||||
|
||||
|
@ -67,20 +67,18 @@ size_t g1m_fcstombs(char *dst, const FONTCHARACTER *src, size_t n)
|
|||
|
||||
/* main loop */
|
||||
while (n--) {
|
||||
if (!*src)
|
||||
break ;
|
||||
|
||||
/* to multi-byte */
|
||||
int count = g1m_fctomb(buf, *src);
|
||||
if ((size_t)count > n)
|
||||
break;
|
||||
int count = g1m_fctomb(buf, *src++);
|
||||
if (count <= 0) break;
|
||||
|
||||
/* copy */
|
||||
if (dst) memcpy(dst, buf, count);
|
||||
dst += count;
|
||||
if (dst) {
|
||||
memcpy(dst, buf, count);
|
||||
dst += count;
|
||||
}
|
||||
len += count;
|
||||
n -= count;
|
||||
}
|
||||
*dst = 0;
|
||||
if (dst) *dst = 0;
|
||||
return (len);
|
||||
}
|
||||
|
|
|
@ -268,14 +268,22 @@ static int eact_parse_line_picture(g1m_line_t *handle, uint8_t *buf,
|
|||
log_info("Picture raw data is:");
|
||||
logm_info(buf, size);
|
||||
|
||||
/* big endian to host endianness */
|
||||
FONTCHARACTER *s = (FONTCHARACTER*)buf;
|
||||
FONTCHARACTER *p = s - 1;
|
||||
while (*(++p)) *p = be16toh(*p);
|
||||
|
||||
/* get the size of the multi-byte string */
|
||||
size_t sz = g1m_fcstombs(NULL, (FONTCHARACTER*)buf, 0);
|
||||
size_t sz = g1m_fcstombs(NULL, s, 0);
|
||||
if (sz == (size_t)-1) return (g1m_error_magic);
|
||||
|
||||
/* make the string */
|
||||
handle->content = malloc(sz + 1);
|
||||
handle->content = malloc(sizeof(FONTCHARACTER) * (sz + 1));
|
||||
if (!handle->content) return (g1m_error_alloc);
|
||||
g1m_fcstombs(handle->content, (FONTCHARACTER*)buf, 0);
|
||||
g1m_fcstombs(handle->content, s, 0);
|
||||
|
||||
/* don't forget to set the handle type! */
|
||||
handle->type = g1m_linetype_picture;
|
||||
|
||||
/* no error */
|
||||
return (0);
|
||||
|
@ -372,6 +380,9 @@ static struct eact_line_type_corresp eact_line_types[] = {
|
|||
static int eact_parse_line(g1m_line_t *handle, uint8_t *buf, size_t size,
|
||||
uint_fast8_t type)
|
||||
{
|
||||
/* initialize handle */
|
||||
handle->type = 0x00;
|
||||
|
||||
/* look for the line type */
|
||||
struct eact_line_type_corresp *linetype = eact_line_types;
|
||||
while (linetype->parse) {
|
||||
|
|
Reference in New Issue