From 454e616e705a3514c2a087a93940bc790f1c623a Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Fri, 6 Apr 2018 15:15:53 +0000 Subject: [PATCH] fixed error number setting issues in hcl_seterrxxx() functions. prefixed internally used encoding conversion functions with hcl_ --- moo/lib/logfmt.c | 12 ++++++------ moo/lib/logfmtv.h | 10 +++++----- moo/lib/moo-utl.h | 43 +++++++++++++++++++++++++++++++++++++++++++ moo/lib/utl.c | 30 ++++++++++++++---------------- 4 files changed, 68 insertions(+), 27 deletions(-) diff --git a/moo/lib/logfmt.c b/moo/lib/logfmt.c index f74fccf..4b64a53 100644 --- a/moo/lib/logfmt.c +++ b/moo/lib/logfmt.c @@ -749,8 +749,6 @@ void moo_seterrbfmt (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, ...) moo_fmtout_t fo; if (moo->shuterr) return; - - moo->errnum = errnum; moo->errmsg.len = 0; fo.mask = 0; /* not used */ @@ -760,6 +758,8 @@ void moo_seterrbfmt (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, ...) va_start (ap, fmt); _errbfmtv (moo, fmt, &fo, ap); va_end (ap); + + moo->errnum = errnum; } void moo_seterrufmt (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, ...) @@ -768,8 +768,6 @@ void moo_seterrufmt (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, ...) moo_fmtout_t fo; if (moo->shuterr) return; - - moo->errnum = errnum; moo->errmsg.len = 0; fo.mask = 0; /* not used */ @@ -779,6 +777,8 @@ void moo_seterrufmt (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, ...) va_start (ap, fmt); _errufmtv (moo, fmt, &fo, ap); va_end (ap); + + moo->errnum = errnum; } @@ -788,7 +788,6 @@ void moo_seterrbfmtv (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, va_ if (moo->shuterr) return; - moo->errnum = errnum; moo->errmsg.len = 0; fo.mask = 0; /* not used */ @@ -796,6 +795,7 @@ void moo_seterrbfmtv (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, va_ fo.putcs = put_errcs; _errbfmtv (moo, fmt, &fo, ap); + moo->errnum = errnum; } void moo_seterrufmtv (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, va_list ap) @@ -804,7 +804,6 @@ void moo_seterrufmtv (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, va_ if (moo->shuterr) return; - moo->errnum = errnum; moo->errmsg.len = 0; fo.mask = 0; /* not used */ @@ -812,4 +811,5 @@ void moo_seterrufmtv (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, va_ fo.putcs = put_errcs; _errufmtv (moo, fmt, &fo, ap); + moo->errnum = errnum; } diff --git a/moo/lib/logfmtv.h b/moo/lib/logfmtv.h index 03d1b6b..c1db3b3 100644 --- a/moo/lib/logfmtv.h +++ b/moo/lib/logfmtv.h @@ -166,7 +166,7 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis /* fmtchar is uch. ooch is bch. convert uch to bch */ ucslen = 1; bcslen = MOO_COUNTOF(bcsbuf); - if (moo_convutooochars(moo, &fch, &ucslen, bcsbuf, &bcslen) <= -1) goto oops; + if (moo_conv_ucsn_to_bcsn_with_cmgr(&fch, &ucslen, bcsbuf, &bcslen, moo->cmgr) <= -1) goto oops; PUT_OOCS (bcsbuf, bcslen); } #endif @@ -467,7 +467,7 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis /* get the length */ for (bslen = 0; bsp[bslen]; bslen++); - if (moo_convbtooochars (moo, bsp, &bslen, MOO_NULL, &slen) <= -1) goto oops; + if (moo_conv_bcsn_to_ucsn_with_cmgr(bsp, &bslen, MOO_NULL, &slen, moo->cmgr, 0) <= -1) goto oops; /* slen holds the length after conversion */ n = slen; @@ -487,7 +487,7 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis conv_len = MOO_COUNTOF(conv_buf); /* this must not fail since the dry-run above was successful */ - moo_convbtooochars (moo, &bsp[tot_len], &src_len, conv_buf, &conv_len); + moo_conv_bcsn_to_ucsn_with_cmgr(&bsp[tot_len], &src_len, conv_buf, &conv_len, moo->cmgr, 0); tot_len += src_len; if (conv_len > n) conv_len = n; @@ -536,7 +536,7 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis /* get the length */ for (uslen = 0; usp[uslen]; uslen++); - if (moo_convutooochars (moo, usp, &uslen, MOO_NULL, &slen) <= -1) goto oops; + if (moo_conv_ucsn_to_bcsn_with_cmgr(usp, &uslen, MOO_NULL, &slen, moo->cmgr) <= -1) goto oops; /* slen holds the length after conversion */ n = slen; @@ -555,7 +555,7 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis conv_len = MOO_COUNTOF(conv_buf); /* this must not fail since the dry-run above was successful */ - moo_convutooochars (moo, &usp[tot_len], &src_len, conv_buf, &conv_len); + moo_conv_ucsn_to_bcsn_with_cmgr (&usp[tot_len], &src_len, conv_buf, &conv_len, moo->cmgr); tot_len += src_len; if (conv_len > n) conv_len = n; diff --git a/moo/lib/moo-utl.h b/moo/lib/moo-utl.h index 0f48676..6aee3bc 100644 --- a/moo/lib/moo-utl.h +++ b/moo/lib/moo-utl.h @@ -345,6 +345,49 @@ MOO_EXPORT int moo_concatoocstrtosbuf ( int id ); +#if defined(MOO_OOCH_IS_UCH) +# define moo_conv_oocs_to_bcs_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) moo_conv_ucs_to_bcs_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) +# define moo_conv_oocsn_to_bcsn_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) moo_conv_ucsn_to_bcsn_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) +#else +# define moo_conv_oocs_to_ucs_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) moo_conv_bcs_to_ucs_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0) +# define moo_conv_oocsn_to_ucsn_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) moo_conv_bcsn_to_ucsn_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0) +#endif + + +MOO_EXPORT int moo_conv_bcs_to_ucs_with_cmgr ( + const moo_bch_t* bcs, + moo_oow_t* bcslen, + moo_uch_t* ucs, + moo_oow_t* ucslen, + moo_cmgr_t* cmgr, + int all +); + +MOO_EXPORT int moo_conv_bcsn_to_ucsn_with_cmgr ( + const moo_bch_t* bcs, + moo_oow_t* bcslen, + moo_uch_t* ucs, + moo_oow_t* ucslen, + moo_cmgr_t* cmgr, + int all +); + +MOO_EXPORT int moo_conv_ucs_to_bcs_with_cmgr ( + const moo_uch_t* ucs, + moo_oow_t* ucslen, + moo_bch_t* bcs, + moo_oow_t* bcslen, + moo_cmgr_t* cmgr +); + +MOO_EXPORT int moo_conv_ucsn_to_bcsn_with_cmgr ( + const moo_uch_t* ucs, + moo_oow_t* ucslen, + moo_bch_t* bcs, + moo_oow_t* bcslen, + moo_cmgr_t* cmgr +); + MOO_EXPORT moo_cmgr_t* moo_get_utf8_cmgr ( void ); diff --git a/moo/lib/utl.c b/moo/lib/utl.c index b3c92de..3647199 100644 --- a/moo/lib/utl.c +++ b/moo/lib/utl.c @@ -327,7 +327,6 @@ moo_bch_t* moo_rfindbchar (const moo_bch_t* ptr, moo_oow_t len, moo_bch_t c) return MOO_NULL; } - moo_uch_t* moo_finducharinucstr (const moo_uch_t* ptr, moo_uch_t c) { while (*ptr != '\0') @@ -349,6 +348,7 @@ moo_bch_t* moo_findbcharinbcstr (const moo_bch_t* ptr, moo_bch_t c) return MOO_NULL; } + /* ----------------------------------------------------------------------- */ int moo_concatoocstrtosbuf (moo_t* moo, const moo_ooch_t* str, int id) @@ -387,10 +387,9 @@ int moo_copyoocstrtosbuf (moo_t* moo, const moo_ooch_t* str, int id) return moo_concatoocstrtosbuf (moo, str, id); } - /* ----------------------------------------------------------------------- */ -static MOO_INLINE int bcsn_to_ucsn_with_cmgr ( +MOO_INLINE int moo_conv_bcsn_to_ucsn_with_cmgr ( const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen, moo_cmgr_t* cmgr, int all) { @@ -511,7 +510,7 @@ static MOO_INLINE int bcsn_to_ucsn_with_cmgr ( return ret; } -static MOO_INLINE int bcs_to_ucs_with_cmgr ( +MOO_INLINE int moo_conv_bcs_to_ucs_with_cmgr ( const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen, moo_cmgr_t* cmgr, int all) { @@ -522,7 +521,7 @@ static MOO_INLINE int bcs_to_ucs_with_cmgr ( for (bp = bcs; *bp != '\0'; bp++) /* nothing */ ; mlen = bp - bcs; wlen = *ucslen; - n = bcsn_to_ucsn_with_cmgr (bcs, &mlen, ucs, &wlen, cmgr, all); + n = moo_conv_bcsn_to_ucsn_with_cmgr (bcs, &mlen, ucs, &wlen, cmgr, all); if (ucs) { /* null-terminate the target buffer if it has room for it. */ @@ -534,7 +533,7 @@ static MOO_INLINE int bcs_to_ucs_with_cmgr ( return n; } -static MOO_INLINE int ucsn_to_bcsn_with_cmgr ( +MOO_INLINE int moo_conv_ucsn_to_bcsn_with_cmgr ( const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen, moo_cmgr_t* cmgr) { @@ -603,8 +602,7 @@ static MOO_INLINE int ucsn_to_bcsn_with_cmgr ( return ret; } - -static int ucs_to_bcs_with_cmgr ( +MOO_INLINE int moo_conv_ucs_to_bcs_with_cmgr ( const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen, moo_cmgr_t* cmgr) { @@ -701,25 +699,25 @@ moo_cmgr_t* moo_get_utf8_cmgr (void) int moo_convutf8touchars (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) { /* the source is length bound */ - return bcsn_to_ucsn_with_cmgr (bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); + return moo_conv_bcsn_to_ucsn_with_cmgr(bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); } int moo_convutoutf8chars (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) { /* length bound */ - return ucsn_to_bcsn_with_cmgr (ucs, ucslen, bcs, bcslen, &utf8_cmgr); + return moo_conv_ucsn_to_bcsn_with_cmgr(ucs, ucslen, bcs, bcslen, &utf8_cmgr); } int moo_convutf8toucstr (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) { /* null-terminated. */ - return bcs_to_ucs_with_cmgr (bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); + return moo_conv_bcs_to_ucs_with_cmgr(bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); } int moo_convutoutf8cstr (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) { /* null-terminated */ - return ucs_to_bcs_with_cmgr (ucs, ucslen, bcs, bcslen, &utf8_cmgr); + return moo_conv_ucs_to_bcs_with_cmgr(ucs, ucslen, bcs, bcslen, &utf8_cmgr); } /* ----------------------------------------------------------------------- */ @@ -729,7 +727,7 @@ int moo_convbtouchars (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* bcslen, moo_ /* length bound */ int n; - n = bcsn_to_ucsn_with_cmgr(bcs, bcslen, ucs, ucslen, moo->cmgr, 0); + n = moo_conv_bcsn_to_ucsn_with_cmgr(bcs, bcslen, ucs, ucslen, moo->cmgr, 0); if (n <= -1) { @@ -745,7 +743,7 @@ int moo_convutobchars (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* ucslen, moo_ /* length bound */ int n; - n = ucsn_to_bcsn_with_cmgr(ucs, ucslen, bcs, bcslen, moo->cmgr); + n = moo_conv_ucsn_to_bcsn_with_cmgr(ucs, ucslen, bcs, bcslen, moo->cmgr); if (n <= -1) { @@ -760,7 +758,7 @@ int moo_convbtoucstr (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* bcslen, moo_u /* null-terminated. */ int n; - n = bcs_to_ucs_with_cmgr(bcs, bcslen, ucs, ucslen, moo->cmgr, 0); + n = moo_conv_bcs_to_ucs_with_cmgr(bcs, bcslen, ucs, ucslen, moo->cmgr, 0); if (n <= -1) { @@ -775,7 +773,7 @@ int moo_convutobcstr (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* ucslen, moo_b /* null-terminated */ int n; - n = ucs_to_bcs_with_cmgr(ucs, ucslen, bcs, bcslen, moo->cmgr); + n = moo_conv_ucs_to_bcs_with_cmgr(ucs, ucslen, bcs, bcslen, moo->cmgr); if (n <= -1) {