On Thu, Jul 31, 2025 at 11:44:16AM +0200, Pavel Sanda wrote:
> On Thu, Jul 31, 2025 at 02:37:06AM +0000, test...@tester.lyx.org wrote:
> >   CXX      Trans.o
> > Trans.cpp: In member function 'const lyx::docstring 
> > lyx::Trans::process(lyx::char_type, lyx::TransManager&)':
> > Trans.cpp:365:40: error: '((const 
> > __gnu_cxx::__alloc_traits<std::allocator<wchar_t>, 
> > wchar_t>::value_type*)((char*)&t + offsetof(const std::__cxx11::docstring, 
> > std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, 
> > std::allocator<wchar_t> >::<unnamed>)))[1]' may be used uninitialized 
> > [-Werror=maybe-uninitialized]
> >   365 |         return k.deadkey(c, 
> > kmod_list_[static_cast<tex_accent>(t[1])]);
> >       |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Trans.cpp:357:25: note: 't' declared here
> >   357 |         docstring const t = match(c);
> >       |                         ^
> 
> 
> I do not know what the code is supposed to do, but clearly we don't test for 
> the combination of
> t.empty() && c = 0
> 
> Can such case appear? If so should we return docstring()?

It's probably better to assert than just access unallocated memory.
I am tempted to commit the attached.
Anyone opinion?

Pavel
diff --git a/src/Trans.cpp b/src/Trans.cpp
index 2a3daf9df0..12086658b1 100644
--- a/src/Trans.cpp
+++ b/src/Trans.cpp
@@ -17,6 +17,7 @@
 
 #include "support/debug.h"
 #include "support/docstream.h"
+#include "support/lassert.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/Lexer.h"
@@ -362,6 +363,8 @@ docstring const Trans::process(char_type c, TransManager & k)
 	if (!t.empty() && t[0] != 0)
 		return t; //return k.normalkey(c);
 
+	LASSERT(t.size()>1, return docstring());
+
 	return k.deadkey(c, kmod_list_[static_cast<tex_accent>(t[1])]);
 }
 
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to