Skip to content

Fix -Wrestrict warning with gcc in initParagraphBidi() - #340

Closed
whistooy wants to merge 1 commit into
desktop-app:masterfrom
whistooy:fix-text-renderer-warning
Closed

whistooy wants to merge 1 commit into
desktop-app:masterfrom
whistooy:fix-text-renderer-warning

Conversation

@whistooy

Copy link
Copy Markdown

GCC assumes _paragraphLength can be negative, which triggers a false-positive -Wrestrict warning during _paragraphAnalysis.resize().

Checking _paragraphLength <= 0 instead of !_paragraphLength prevents the compiler from assuming the length might be negative and cleanly silences the warning.

Build log
In function 'void* memcpy(void*, const void*, size_t)',
    inlined from 'void QtPrivate::q_uninitialized_relocate_n(T*, N, T*) [with T = QScriptAnalysis; N = long long int]' at /usr/include/qt6/QtCore/qcontainertools_impl.h:79:24,
    inlined from 'void QtPrivate::q_uninitialized_relocate_n(T*, N, T*) [with T = QScriptAnalysis; N = long long int]' at /usr/include/qt6/QtCore/qcontainertools_impl.h:73:6,
    inlined from 'void QVLABase<T>::reallocate_impl(qsizetype, void*, qsizetype, qsizetype) [with T = QScriptAnalysis]' at /usr/include/qt6/QtCore/qvarlengtharray.h:939:46,
    inlined from 'void QVLABase<T>::resize_impl(qsizetype, void*, qsizetype) [with T = QScriptAnalysis]' at /usr/include/qt6/QtCore/qvarlengtharray.h:251:24,
    inlined from 'void QVarLengthArray<T, Prealloc>::resize(qsizetype) [with T = QScriptAnalysis; long long int Prealloc = 4096]' at /usr/include/qt6/QtCore/qvarlengtharray.h:455:50,
    inlined from 'void Ui::Text::Renderer::initParagraphBidi()' at ui/text/text_renderer.cpp:542:27:
/usr/include/bits/string_fortified.h:29:33: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' accessing 18446744065119617024 or more bytes at offsets 31208 and 0 overlaps 9223372019674906625 bytes at offset -9223372028264841217 [-Wrestrict]
   29 |   return __builtin___memcpy_chk (__dest, __src, __len,
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
   30 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~

Silence a false positive GCC warning. Checking _paragraphLength <= 0 prevents the compiler from thinking the length might be negative.
@ilya-fedin

Copy link
Copy Markdown
Contributor

Why this warning isn't present in official builds? 🤔 They're built with -Werror...

@whistooy

Copy link
Copy Markdown
Author

Why this warning isn't present in official builds? 🤔 They're built with -Werror...

Probably just toolchain differences. On my setup (GCC 15.3, glibc 2.43 with fortify defaults), GCC inlines __memcpy_chk in QVarLengthArray::resize and gets confused by the signed length. Small changes like PCH or inlining flags locally make the warning show up or go away, so makes sense why CI never hits it.

@whistooy

Copy link
Copy Markdown
Author

Closing as superseded by 0b5bae2.

Tested on master with the same setup and the warning is gone. Moving the array to the heap means GCC no longer tracks the struct offset for overlap warnings, so this shouldn't pop up again anyway. Thanks!

@whistooy whistooy closed this Sep 15, 2026
@whistooy
whistooy deleted the fix-text-renderer-warning branch September 15, 2026 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants