<div dir="ltr"><div>Hi,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 23, 2022 at 8:37 PM Siddharth Khattar <<a href="mailto:skhattar111@gmail.com">skhattar111@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello all,<br>
<br>
So I was aiming to do a medium difficulty level easy hack and came<br>
across this one (Bug 90341) which interested me. I then studied what<br>
const_cast does and what was the main issue that this bug was<br>
addressing. As I looked into it more and ran the command " git grep<br>
--word-regexp --count const_cast | sort --numeric-sort --key=2<br>
--field-separator=: ", I got various results and decided to look into<br>
core/xmloff/source/style/impastpl.cxx (lines 144 & 146).<br>
I also decided to go through the previous commits made in the bug<br>
thread for ideas and help, such as these:<br>
<a href="https://git.libreoffice.org/core/+/7b152167a4e4c3eaac95aee8f282873681c90092%5E%21" rel="noreferrer" target="_blank">https://git.libreoffice.org/core/+/7b152167a4e4c3eaac95aee8f282873681c90092%5E%21</a><br>
and <a href="https://cgit.freedesktop.org/libreoffice/core/commit/?id=4ae319ae462f3f094452046e392c8c15446736ae" rel="noreferrer" target="_blank">https://cgit.freedesktop.org/libreoffice/core/commit/?id=4ae319ae462f3f094452046e392c8c15446736ae</a>.<br>
I then decided to experiment with the file (impastpl.cxx) and then<br>
removed const & const_cast from the above-mentioned lines. Then, when<br>
I tried to build from source I got these errors (please see attached<br>
text file).<br>
<br>
I wasn't sure what to make of these errors as nothing helpful came<br>
when I googled them & I also am not heavily experienced in c++ coding.<br>
Then I started reading some documentation of the xmloff file to come<br>
to understand that these files were related to outputting "basic ODF<br>
import/export filter implementation for most applications".<br>
<br>
One of the people at LibreOffice (buovjaga) also helped me with this<br>
and pointed out that the any2string function in that file appeared in:<br>
<a href="https://git.libreoffice.org/core/commit/c1015fdd51909495cefdc0258c3899cd73d4d2df" rel="noreferrer" target="_blank">https://git.libreoffice.org/core/commit/c1015fdd51909495cefdc0258c3899cd73d4d2df</a>.<br>
I pondered about contacting the original contributor who pushed this<br>
commit for help but as the commit was 9+ years old I dropped that idea<br>
pretty quickly<br>
I'd really appreciate it if the dev team could help me in any way with<br>
this easy hack and tell me in which direction I should go!<br></blockquote><div><br></div><div>It's quite simple - if a variable is const it means it should not be changed. any.getValue() is returning such a variable (const void*), but the variable is then put into data2string function, which accepts a non-const variable that can be changed (void*).</div><div>So if you don't o a const_cast, the compiler will complain that you can't put a variable that is said to be unchangeable into a function where it requires the variable to be changeable, so it complains that it can't do that.</div><div><br></div><div>This is the reason there was/is a const_cast at that place, which says that "the compiler is dumb and doesn't know what's talking about so covert that unchangable variable to be changeable so the compiler is silent and stops bugging the developers". <br></div><div><br></div><div>So how to solve this - at least in this case: looking at the data2string function the "void* data" input variable is later on cast to a const something variable anyway, so maybe try to change the input variable type from "void* data" to "const void* data" and fix any issues you have later on in the body with this data variable.</div><div><br></div><div>Also note that in another const_cast case the situation might be different and you must check how to solve the issue on a case by case basis (some possible solutions are in the bug report)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanking you for your time,<br>
Siddharth Khattar<br></blockquote><div><br></div><div>Tomaž <br></div></div></div>