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

Re: Bug#889596: libpinyin: FTBFS on sparc64: bus error in gen_binary_files



Control: tags -1 +patch

Hi Aaron,

On Sun, 2018-02-04 at 16:31 -0500, Aaron M. Ucko wrote:
> Builds of libpinyin for sparc64 (admittedly not a release architecture)
> have been failing:
> 
>   ../utils/storage/gen_binary_files --table-dir ../data
>   Makefile:539: recipe for target 'bigram.db' failed
>   make[3]: *** [bigram.db] Bus error
> 
> This error most likely indicates an unaligned memory access attempt, to
> which sparc64 is particularly sensitive.  Could you please take a look?

This is trivially fixed by:

diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp
index bb98251..e88e6e9 100644
--- a/src/storage/phrase_index.cpp
+++ b/src/storage/phrase_index.cpp
@@ -647,7 +647,9 @@ int SubPhraseIndex::get_range(/* out */ PhraseIndexRange & range){
     /* remove trailing zeros. */
     const table_offset_t * poffset = NULL;
     for (poffset = end; poffset > begin + 1; --poffset) {
-        if (0 !=  *(poffset - 1))
+        table_offset_t value;
+        memcpy(&value, poffset - 1, sizeof(value));
+        if (0 != value)
             break;
     }
 
I have opened a pull request upstream [1] and I'm attaching my patch.

Adrian

> [1] https://github.com/libpinyin/libpinyin/pull/171

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
From 8030d09280438e22e61aa75cb08c498f9adbcd30 Mon Sep 17 00:00:00 2001
From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Date: Thu, 30 Oct 2025 09:12:14 +0100
Subject: [PATCH] Fix unaligned access in get_range()

---
 src/storage/phrase_index.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp
index bb98251..e88e6e9 100644
--- a/src/storage/phrase_index.cpp
+++ b/src/storage/phrase_index.cpp
@@ -647,7 +647,9 @@ int SubPhraseIndex::get_range(/* out */ PhraseIndexRange & range){
     /* remove trailing zeros. */
     const table_offset_t * poffset = NULL;
     for (poffset = end; poffset > begin + 1; --poffset) {
-        if (0 !=  *(poffset - 1))
+        table_offset_t value;
+        memcpy(&value, poffset - 1, sizeof(value));
+        if (0 != value)
             break;
     }
 
-- 
2.47.3


Reply to: