Merge lp:~wgrant/pygettextpo/bug-1269662 into lp:pygettextpo

Proposed by William Grant
Status: Merged
Merged at revision: 25
Proposed branch: lp:~wgrant/pygettextpo/bug-1269662
Merge into: lp:pygettextpo
Diff against target: 40 lines (+6/-4)
1 file modified
gettextpo.c (+6/-4)
To merge this branch: bzr merge lp:~wgrant/pygettextpo/bug-1269662
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Launchpad PQM Bot Pending
Review via email: mp+201874@code.launchpad.net

Commit message

Fix set_msgstr, set_msgstr_plural and set_comments to not segfault when given None on gettext >= 0.18.2.

Description of the change

Fix set_msgstr, set_msgstr_plural and set_comments to not segfault when given None on gettext >= 0.18.2.

set_msgstr(None) tries to set the msgstr to NULL, despite po_message_set_msgstr being documented as taking a string, with "" being used to represent the lack of a translation. Despite being illegal, setting them to NULL works fine in old gettexts, as po_message_set_msgstr is a no-op if the value hasn't changed. However, gettext 0.18.2 switches the default strings in a message from NULL to "", so po_message_set_msgstr(msg, NULL) is no longer a no-op, and it segfaults.

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) wrote :

Looks very good, assuming the gettext version on precise will not choke when given empty strings instead of NULL (by the facts the documentation has not been extremely accurate in this subject).
Let's make LP way to trusty ...

review: Approve
lp:~wgrant/pygettextpo/bug-1269662 updated
26. By William Grant

Fix check_format to bail out early if the msgid or msgstr are "" or None, to cope with the new "" default.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'gettextpo.c'
--- gettextpo.c 2009-06-02 15:31:25 +0000
+++ gettextpo.c 2014-01-16 03:06:38 +0000
@@ -610,7 +610,7 @@
610 return NULL;610 return NULL;
611611
612 if (object == Py_None) {612 if (object == Py_None) {
613 po_message_set_msgstr(self->msg, NULL);613 po_message_set_msgstr(self->msg, "");
614 } else {614 } else {
615 string = get_pystring_from_pyobject(object);615 string = get_pystring_from_pyobject(object);
616616
@@ -651,7 +651,7 @@
651 }651 }
652652
653 if (object == Py_None) {653 if (object == Py_None) {
654 po_message_set_msgstr_plural(self->msg, index, NULL);654 po_message_set_msgstr_plural(self->msg, index, "");
655 } else {655 } else {
656 string = get_pystring_from_pyobject(object);656 string = get_pystring_from_pyobject(object);
657657
@@ -683,7 +683,7 @@
683 return NULL;683 return NULL;
684684
685 if (object == Py_None) {685 if (object == Py_None) {
686 po_message_set_comments(self->msg, NULL);686 po_message_set_comments(self->msg, "");
687 } else {687 } else {
688 string = get_pystring_from_pyobject(object);688 string = get_pystring_from_pyobject(object);
689689
@@ -741,7 +741,9 @@
741 * provide the same behaviour as old versions.741 * provide the same behaviour as old versions.
742 */742 */
743 if (po_message_msgid(self->msg) == NULL ||743 if (po_message_msgid(self->msg) == NULL ||
744 po_message_msgstr(self->msg) == NULL) {744 strlen(po_message_msgid(self->msg)) == 0 ||
745 po_message_msgstr(self->msg) == NULL ||
746 strlen(po_message_msgstr(self->msg)) == 0) {
745 Py_RETURN_NONE;747 Py_RETURN_NONE;
746 }748 }
747749

Subscribers

People subscribed via source and target branches