Skip to content

Commit

Permalink
Merge pull request #542 from chewing/msvc-2022-fixes
Browse files Browse the repository at this point in the history
fix: chewing_Reset miscompile on MSVC 2022
  • Loading branch information
kanru committed May 17, 2024
2 parents e07be26 + db73070 commit dd036b1
Showing 1 changed file with 8 additions and 48 deletions.
56 changes: 8 additions & 48 deletions src/chewingio.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,67 +307,27 @@ CHEWING_API ChewingContext *chewing_new()
CHEWING_API int chewing_Reset(ChewingContext *ctx)
{
ChewingData *pgdata;
ChewingStaticData staticData;
ChewingConfigData old_config;
void (*logger) (void *data, int level, const char *fmt, ...);
void *loggerData;
#ifdef WITH_RUST
const void *dict;
void *ce;
void *ue;
#endif
ChewingData data;

if (!ctx) {
return -1;
}

pgdata = ctx->data;

LOG_API("");

/* Backup old config and restore it after clearing pgdata structure. */
old_config = pgdata->config;
staticData = pgdata->staticData;
logger = pgdata->logger;
loggerData = pgdata->loggerData;
#ifdef WITH_RUST
dict = pgdata->dict;
ce = pgdata->ce;
ue = pgdata->ue;
if (pgdata->bopomofoData.editorWithKeymap != 0) {
FreePhoneticEditor(pgdata->bopomofoData.editorWithKeymap);
}
#endif
memset(pgdata, 0, sizeof(ChewingData));
pgdata->config = old_config;
pgdata->staticData = staticData;
pgdata->logger = logger;
pgdata->loggerData = loggerData;
data = *pgdata;

#ifdef WITH_RUST
pgdata->dict = dict;
pgdata->ce = ce;
pgdata->ue = ue;
chewing_set_KBType(ctx, KB_DEFAULT);
#else
/* bopomofoData */
memset(&(pgdata->bopomofoData), 0, sizeof(BopomofoData));
#endif

/* choiceInfo */
memset(&(pgdata->choiceInfo), 0, sizeof(ChoiceInfo));

pgdata->chiSymbolCursor = 0;
pgdata->chiSymbolBufLen = 0;
pgdata->nPhoneSeq = 0;
memset(pgdata->bUserArrCnnct, 0, sizeof(int) * (MAX_PHONE_SEQ_LEN + 1));
memset(pgdata->bUserArrBrkpt, 0, sizeof(int) * (MAX_PHONE_SEQ_LEN + 1));
memset(pgdata, 0, sizeof(ChewingData));
pgdata->config = data.config;
pgdata->staticData = data.staticData;
pgdata->logger = data.logger;
pgdata->loggerData = data.loggerData;
pgdata->bChiSym = CHINESE_MODE;
pgdata->bFullShape = HALFSHAPE_MODE;
pgdata->bSelect = 0;
pgdata->nSelect = 0;
pgdata->pointStart = -1;
pgdata->pointEnd = 0;
pgdata->phrOut.nNumCut = 0;
return 0;
}

Expand Down

0 comments on commit dd036b1

Please sign in to comment.