unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#50764: Fix (string-distance "" "") edge-case
@ 2021-09-23 16:16 Philip Kaludercic
  2021-09-23 17:12 ` Mattias Engdegård
  0 siblings, 1 reply; 2+ messages in thread
From: Philip Kaludercic @ 2021-09-23 16:16 UTC (permalink / raw)
  To: 50764

[-- Attachment #1: Type: text/plain, Size: 820 bytes --]

Tags: patch


string-distance appears to be using uninitialized memory, if the second
argument is an empty string. This leads to the function occasionally
generating random and meaningless results. This patch ensures that the
entire memory is initialized before it is accessed, fixing the results
for edge cases with empty strings.

In GNU Emacs 28.0.50 (build 13, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars)
 of 2021-09-23 built on icterid
Repository revision: bb5d8582f75712c3610795aa5ead79600308f8bb
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure LDFLAGS=-flto 'CFLAGS=-O2 -march=native -mtune=native -pipe'
 --with-native-compilation PKG_CONFIG_PATH='


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-string-distance-for-two-empty-strings.patch --]
[-- Type: text/patch, Size: 752 bytes --]

From fbc62cb035fe2a674c9834c6bdcef5c5d2af85e2 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Thu, 23 Sep 2021 18:12:41 +0200
Subject: [PATCH] Fix string-distance for two empty strings

* fns.c (Fstring_distance): Avoid using uninitialized memory
---
 src/fns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/fns.c b/src/fns.c
index 4e74589ef2..a72e41aee5 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -322,7 +322,7 @@ DEFUN ("string-distance", Fstring_distance, Sstring_distance, 2, 3, 0,
 
   USE_SAFE_ALLOCA;
   ptrdiff_t *column = SAFE_ALLOCA ((len1 + 1) * sizeof (ptrdiff_t));
-  for (y = 1; y <= len1; y++)
+  for (y = 0; y <= len1; y++)
     column[y] = y;
 
   if (use_byte_compare)
-- 
2.30.2


[-- Attachment #3: Type: text/plain, Size: 16 bytes --]


-- 
	Philip K.

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#50764: Fix (string-distance "" "") edge-case
  2021-09-23 16:16 bug#50764: Fix (string-distance "" "") edge-case Philip Kaludercic
@ 2021-09-23 17:12 ` Mattias Engdegård
  0 siblings, 0 replies; 2+ messages in thread
From: Mattias Engdegård @ 2021-09-23 17:12 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 50764-done

Looks like your independent test suite is already paying dividends!
Pushed with tests.






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-23 17:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-23 16:16 bug#50764: Fix (string-distance "" "") edge-case Philip Kaludercic
2021-09-23 17:12 ` Mattias Engdegård

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).