emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 962562c: Fix inverted NOCOPY encode/decode parameter (bug#40407)


From: Mattias Engdegård
Subject: master 962562c: Fix inverted NOCOPY encode/decode parameter (bug#40407)
Date: Sun, 5 Apr 2020 05:46:14 -0400 (EDT)

branch: master
commit 962562cde45071f74a37854a299e88470a4ecd49
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    Fix inverted NOCOPY encode/decode parameter (bug#40407)
    
    In {encode,decode}-coding-string, the NOCOPY parameter had the
    opposite effect to what was intended and documented.  This 18 year old
    bug (introduced in 4031e2bf0a) only affected calls with CODING-SYSTEM
    being nil.
    
    * src/coding.c (code_convert_string): Correct use of NOCOPY.
    * test/src/coding-tests.el (coding-nocopy-trivial): New test.
---
 src/coding.c             | 2 +-
 test/src/coding-tests.el | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/coding.c b/src/coding.c
index f0fc37d..1049f1b 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -9485,7 +9485,7 @@ code_convert_string (Lisp_Object string, Lisp_Object 
coding_system,
       if (! norecord)
        Vlast_coding_system_used = Qno_conversion;
       if (NILP (dst_object))
-       return (nocopy ? Fcopy_sequence (string) : string);
+       return nocopy ? string : Fcopy_sequence (string);
     }
 
   if (NILP (coding_system))
diff --git a/test/src/coding-tests.el b/test/src/coding-tests.el
index 094a1fa..110ff12 100644
--- a/test/src/coding-tests.el
+++ b/test/src/coding-tests.el
@@ -375,6 +375,14 @@
                         (with-temp-buffer (insert-file-contents (car file))))))
          (insert (format "%s: %s\n" (car file) result)))))))
 
+(ert-deftest coding-nocopy-trivial ()
+  "Check that the NOCOPY parameter works for the trivial coding system."
+  (let ((s "abc"))
+    (should-not (eq (decode-coding-string s nil nil) s))
+    (should (eq (decode-coding-string s nil t) s))
+    (should-not (eq (encode-coding-string s nil nil) s))
+    (should (eq (encode-coding-string s nil t) s))))
+
 ;; Local Variables:
 ;; byte-compile-warnings: (not obsolete)
 ;; End:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]