summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxhe <xw897002528@gmail.com>2017-10-04 10:06:32 +0800
committerxhe <xw897002528@gmail.com>2017-10-16 13:00:29 +0800
commit57f10174a0c15f63d949ec154c5ffff71a09c75e (patch)
tree701be2b5bf7b52a44d3e8111c18ace75f8ac46ff
parent49b056766f3b77a9909f96df13ba269d75250e21 (diff)
downloadgettext-tiny-57f10174a0c15f63d949ec154c5ffff71a09c75e.tar.gz
fix: writestr() should do nothing when empty .po
https://github.com/sabotage-linux/gettext-tiny/issues/14. At line:439, writestr() is called to write down those strings that have not been wrote down in the main loop. When po files are empty, nothing is wrote down, so d->plurals_count == 0. Then, deleting 'invalid' codes in writestr() was executed wrongly. -1 is not a valid index, qsort will segfault, of course. To fix the bug, we check d->num[pe_msgid]>0, so it will do nothing when the files are empty.
-rw-r--r--src/msgfmt.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/msgfmt.c b/src/msgfmt.c
index 26e8c3e..d9db752 100644
--- a/src/msgfmt.c
+++ b/src/msgfmt.c
@@ -248,7 +248,10 @@ static inline void writemsg(struct callbackdata *d) {
static inline void writestr(struct callbackdata *d, struct po_info *info) {
// msgid xx; msgstr ""; is widely happened, it's invalid
- if(!d->pluralstr_count) {
+
+ // https://github.com/sabotage-linux/gettext-tiny/issues/1
+ // no invalid, when empty, check d->num[pe_msgid]
+ if(!d->pluralstr_count && d->num[pe_msgid] > 0) {
d->len[pe_msgid]-=d->msgidbuf1_len;
d->len[pe_msgid]-=d->msgidbuf2_len;
d->len[pe_plural]-=d->pluralbuf1_len;