Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 788513 Details for
Bug 854738
app-misc/sphinx-2.2.11-r5 fails to compile (lto): sphinxudf.c:305:17: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch that avoids undefined behaviour because of c++ reinterpret_cast
0001-Move-sphinxudf-to-cpp.patch (text/plain), 10.50 KB, created by
Andreas Kölbl
on 2022-06-28 16:17:48 UTC
(
hide
)
Description:
Patch that avoids undefined behaviour because of c++ reinterpret_cast
Filename:
MIME Type:
Creator:
Andreas Kölbl
Created:
2022-06-28 16:17:48 UTC
Size:
10.50 KB
patch
obsolete
>From a8706f3eb3a840a9048de54e67eadc2126bf7dac Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Andreas=20K=C3=B6lbl?= <koelblandreas@gentoo.org> >Date: Tue, 28 Jun 2022 17:57:28 +0200 >Subject: [PATCH] Move sphinxudf to cpp > >C++ allows for reinterpret cast and avoids undefined behaviour because >of type punning. The project aims to provide cpp code anyways and the >ammended code should not change. >--- > codeblocks/libsphinx.cbp | 2 +- > doc/sphinx.html | 8 ++++---- > doc/sphinx.txt | 8 ++++---- > doc/sphinx.xml | 8 ++++---- > src/CMakeLists.txt | 2 +- > src/Makefile.am | 2 +- > src/Makefile.in | 2 +- > src/{sphinxudf.c => sphinxudf.cpp} | 4 ++-- > win/libsphinx12.vcxproj | 2 +- > win/libsphinx13.vcxproj | 2 +- > 10 files changed, 20 insertions(+), 20 deletions(-) > rename src/{sphinxudf.c => sphinxudf.cpp} (99%) > >diff --git a/codeblocks/libsphinx.cbp b/codeblocks/libsphinx.cbp >index 2590f6b..eb5e53c 100644 >--- a/codeblocks/libsphinx.cbp >+++ b/codeblocks/libsphinx.cbp >@@ -74,7 +74,7 @@ > <Unit filename="../src/sphinxstemcz.cpp" /> > <Unit filename="../src/sphinxstemen.cpp" /> > <Unit filename="../src/sphinxstemru.cpp" /> >- <Unit filename="../src/sphinxudf.c"> >+ <Unit filename="../src/sphinxudf.cpp"> > <Option compilerVar="CC" /> > </Unit> > <Unit filename="../src/sphinxutils.cpp" /> >diff --git a/doc/sphinx.html b/doc/sphinx.html >index b56e445..bb30cdc 100644 >--- a/doc/sphinx.html >+++ b/doc/sphinx.html >@@ -3665,12 +3665,12 @@ header file definitions of a few UDF related structures and types. For most > UDFs and plugins, a mere <code class="code">#include "sphinxudf.h"</code>, like in the example, > should be completely sufficient, too. However, if you're writing a ranking function and > need to access the ranking signals (factors) data from within the UDF, you will >-also need to compile and link with <code class="filename">src/sphinxudf.c</code> (also >+also need to compile and link with <code class="filename">src/sphinxudf.cpp</code> (also > available in our source code), because the <span class="emphasis"><em>implementations</em></span> > of the fuctions that let you access the signal data from within the UDF reside > in that file. > </p><p> >-Both <code class="filename">sphinxudf.h</code> header and <code class="filename">sphinxudf.c</code> >+Both <code class="filename">sphinxudf.h</code> header and <code class="filename">sphinxudf.cpp</code> > are standalone. So you can copy around those files only; they do not depend > on any other bits of Sphinx source code. > </p><p> >@@ -3888,8 +3888,8 @@ Just as with UDFs, you want to include <code class="filename">src/sphinxudf.h</c > header file. At the very least, you will need the SPH_UDF_VERSION > constant to implement a proper version function. Depending on the specific > plugin type, you might or might not need to link your plugin with >-<code class="filename">src/sphinxudf.c</code>. However, as of 2.2.2-beta all >-the functions implemented in <code class="filename">sphinxudf.c</code> are about >+<code class="filename">src/sphinxudf.cpp</code>. However, as of 2.2.2-beta all >+the functions implemented in <code class="filename">sphinxudf.cpp</code> are about > unpacking the PACKEDFACTORS() blob, and no plugin types are exposed to that > kind of data. So currently, you would never need to link with the C-file, > just the header would be sufficient. (In fact, if you copy over the >diff --git a/doc/sphinx.txt b/doc/sphinx.txt >index ed994f9..b4a2b65 100644 >--- a/doc/sphinx.txt >+++ b/doc/sphinx.txt >@@ -4280,11 +4280,11 @@ related structures and types. For most UDFs and plugins, a mere #include > "sphinxudf.h", like in the example, should be completely sufficient, too. > However, if you're writing a ranking function and need to access the > ranking signals (factors) data from within the UDF, you will also need to >-compile and link with src/sphinxudf.c (also available in our source code), >+compile and link with src/sphinxudf.cpp (also available in our source code), > because the implementations of the fuctions that let you access the signal > data from within the UDF reside in that file. > >-Both sphinxudf.h header and sphinxudf.c are standalone. So you can copy >+Both sphinxudf.h header and sphinxudf.cpp are standalone. So you can copy > around those files only; they do not depend on any other bits of Sphinx > source code. > >@@ -4490,8 +4490,8 @@ and plugin; that is up to you. > Just as with UDFs, you want to include src/sphinxudf.h header file. At the > very least, you will need the SPH_UDF_VERSION constant to implement > a proper version function. Depending on the specific plugin type, you might >-or might not need to link your plugin with src/sphinxudf.c. However, as of >-2.2.2-beta all the functions implemented in sphinxudf.c are about unpacking >+or might not need to link your plugin with src/sphinxudf.cpp. However, as of >+2.2.2-beta all the functions implemented in sphinxudf.cpp are about unpacking > the PACKEDFACTORS() blob, and no plugin types are exposed to that kind of > data. So currently, you would never need to link with the C-file, just the > header would be sufficient. (In fact, if you copy over the UDF version >diff --git a/doc/sphinx.xml b/doc/sphinx.xml >index bdfb125..d7f44b8 100644 >--- a/doc/sphinx.xml >+++ b/doc/sphinx.xml >@@ -4094,13 +4094,13 @@ header file definitions of a few UDF related structures and types. For most > UDFs and plugins, a mere <code>#include "sphinxudf.h"</code>, like in the example, > should be completely sufficient, too. However, if you're writing a ranking function and > need to access the ranking signals (factors) data from within the UDF, you will >-also need to compile and link with <filename>src/sphinxudf.c</filename> (also >+also need to compile and link with <filename>src/sphinxudf.cpp</filename> (also > available in our source code), because the <emphasis>implementations</emphasis> > of the fuctions that let you access the signal data from within the UDF reside > in that file. > </para> > <para> >-Both <filename>sphinxudf.h</filename> header and <filename>sphinxudf.c</filename> >+Both <filename>sphinxudf.h</filename> header and <filename>sphinxudf.cpp</filename> > are standalone. So you can copy around those files only; they do not depend > on any other bits of Sphinx source code. > </para> >@@ -4336,8 +4336,8 @@ Just as with UDFs, you want to include <filename>src/sphinxudf.h</filename> > header file. At the very least, you will need the SPH_UDF_VERSION > constant to implement a proper version function. Depending on the specific > plugin type, you might or might not need to link your plugin with >-<filename>src/sphinxudf.c</filename>. However, as of 2.2.2-beta all >-the functions implemented in <filename>sphinxudf.c</filename> are about >+<filename>src/sphinxudf.cpp</filename>. However, as of 2.2.2-beta all >+the functions implemented in <filename>sphinxudf.cpp</filename> are about > unpacking the PACKEDFACTORS() blob, and no plugin types are exposed to that > kind of data. So currently, you would never need to link with the C-file, > just the header would be sufficient. (In fact, if you copy over the >diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt >index 469e47b..1c99e02 100644 >--- a/src/CMakeLists.txt >+++ b/src/CMakeLists.txt >@@ -8,7 +8,7 @@ set (LIBSPHINX_SRCS sphinx.cpp sphinxexcerpt.cpp > sphinxsort.cpp sphinxexpr.cpp sphinxfilter.cpp > sphinxsearch.cpp sphinxrt.cpp sphinxjson.cpp > sphinxaot.cpp sphinxplugin.cpp >- sphinxudf.c) >+ sphinxudf.cpp) > set (INDEXER_SRCS indexer.cpp) > set (INDEXTOOL_SRCS indextool.cpp) > set (SEARCHD_SRCS searchd.cpp) >diff --git a/src/Makefile.am b/src/Makefile.am >index 048a112..b5f56b8 100644 >--- a/src/Makefile.am >+++ b/src/Makefile.am >@@ -1,7 +1,7 @@ > SRC_SPHINX = sphinx.cpp sphinxexcerpt.cpp sphinxquery.cpp \ > sphinxsoundex.cpp sphinxmetaphone.cpp sphinxstemen.cpp sphinxstemru.cpp sphinxstemcz.cpp sphinxstemar.cpp \ > sphinxutils.cpp sphinxstd.cpp sphinxsort.cpp sphinxexpr.cpp sphinxfilter.cpp \ >- sphinxsearch.cpp sphinxrt.cpp sphinxjson.cpp sphinxudf.c sphinxaot.cpp sphinxplugin.cpp >+ sphinxsearch.cpp sphinxrt.cpp sphinxjson.cpp sphinxudf.cpp sphinxaot.cpp sphinxplugin.cpp > > noinst_LIBRARIES = libsphinx.a > libsphinx_a_SOURCES = $(SRC_SPHINX) >diff --git a/src/Makefile.in b/src/Makefile.in >index d6fd90b..84d956c 100644 >--- a/src/Makefile.in >+++ b/src/Makefile.in >@@ -222,7 +222,7 @@ top_srcdir = @top_srcdir@ > SRC_SPHINX = sphinx.cpp sphinxexcerpt.cpp sphinxquery.cpp \ > sphinxsoundex.cpp sphinxmetaphone.cpp sphinxstemen.cpp sphinxstemru.cpp sphinxstemcz.cpp sphinxstemar.cpp \ > sphinxutils.cpp sphinxstd.cpp sphinxsort.cpp sphinxexpr.cpp sphinxfilter.cpp \ >- sphinxsearch.cpp sphinxrt.cpp sphinxjson.cpp sphinxudf.c sphinxaot.cpp sphinxplugin.cpp >+ sphinxsearch.cpp sphinxrt.cpp sphinxjson.cpp sphinxudf.cpp sphinxaot.cpp sphinxplugin.cpp > > noinst_LIBRARIES = libsphinx.a > libsphinx_a_SOURCES = $(SRC_SPHINX) >diff --git a/src/sphinxudf.c b/src/sphinxudf.cpp >similarity index 99% >rename from src/sphinxudf.c >rename to src/sphinxudf.cpp >index e831910..6c2f838 100644 >--- a/src/sphinxudf.c >+++ b/src/sphinxudf.cpp >@@ -302,14 +302,14 @@ int sphinx_get_term_factor_int ( const unsigned int * in, enum sphinx_term_facto > float sphinx_get_field_factor_float ( const unsigned int * in, enum sphinx_field_factor f ) > { > int r = sphinx_get_field_factor_int ( in, f ); >- return *(float*)&r; >+ return *reinterpret_cast<float*>(&r); > } > > > float sphinx_get_term_factor_float ( const unsigned int * in, enum sphinx_term_factor f ) > { > int r = sphinx_get_term_factor_int ( in, f ); >- return *(float*)&r; >+ return *reinterpret_cast<float*>(&r); > } > > // >diff --git a/win/libsphinx12.vcxproj b/win/libsphinx12.vcxproj >index ec54f3e..621b024 100644 >--- a/win/libsphinx12.vcxproj >+++ b/win/libsphinx12.vcxproj >@@ -155,7 +155,7 @@ > <ClCompile Include="..\src\sphinxstemcz.cpp" /> > <ClCompile Include="..\src\sphinxstemen.cpp" /> > <ClCompile Include="..\src\sphinxstemru.cpp" /> >- <ClCompile Include="..\src\sphinxudf.c" /> >+ <ClCompile Include="..\src\sphinxudf.cpp" /> > <ClCompile Include="..\src\sphinxutils.cpp" /> > </ItemGroup> > <ItemGroup> >diff --git a/win/libsphinx13.vcxproj b/win/libsphinx13.vcxproj >index cc2a5d4..0fcbb33 100644 >--- a/win/libsphinx13.vcxproj >+++ b/win/libsphinx13.vcxproj >@@ -177,7 +177,7 @@ > <ClCompile Include="..\src\sphinxstemcz.cpp" /> > <ClCompile Include="..\src\sphinxstemen.cpp" /> > <ClCompile Include="..\src\sphinxstemru.cpp" /> >- <ClCompile Include="..\src\sphinxudf.c" /> >+ <ClCompile Include="..\src\sphinxudf.cpp" /> > <ClCompile Include="..\src\sphinxutils.cpp" /> > </ItemGroup> > <ItemGroup> >-- >2.35.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 854738
:
788249
| 788513