Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PopulateBidiChain in some situations leaves SBBidiType portion of memory uninitialized. #19

Open
RafalWawrzyniak-TomTom opened this issue Aug 23, 2022 · 3 comments · May be fixed by #21

Comments

@RafalWawrzyniak-TomTom
Copy link

I checked with valgrind that on every run it reports
"==2247== Warning: unimplemented fcntl command: 1033
==2247== Thread 32:
==2247== Conditional jump or move depends on uninitialised value(s)
==2247== at 0x14B4107: SBAlgorithmCreateParagraph"
I tried to narrow down the part of memory which is uninitialized according to valgrind and it came out that if I will add in CreateParagraphContext function just after BidiChainInitialize additional code

for (int i = 0;i < length;++i) fixedTypes[i] = SBBidiTypeNil;

the valgrind is not reporting any problem.

I followed PopulateBidiChain code and it looks that in some cases it can omit initialization of some links in the chain. I do not understand sheenbidi well enough to say if this mean we have a data error in such case. Anyway application is not crashing because of it, the only visible problem so far is valgrind report.

@mta452
Copy link
Member

mta452 commented Aug 26, 2022

This can be safely ignored since uninitalized links are never read anyway. Basically it mimicks a linked list but with a pre allocated array. This helps overcome the malloc overhead of nodes.

The chain is iterated from the links indexes array, so it will always access a valid link.

@DominiquePelle-TomTom
Copy link

DominiquePelle-TomTom commented Mar 20, 2023

@mta452 wrote:

This can be safely ignored since uninitalized links are never read anyway.

That is still annoying, even if it presumably does not have bad consequences in this case.

One would expect to have clean report from valgrind, otherwise it becomes nearly impossible to know what's fine and what is done when checking software that integrates many 3rd party libs.

To be pedantic, a condition that depends on uninitialized memory is undefined behavior, and UB is always a bug (which may or may not have consequences in some cases, but that's unpredictable on all toolchains/platforms).

@InfoTeddy
Copy link

for (int i = 0;i < length;++i) fixedTypes[i] = SBBidiTypeNil;

This is incorrect, because the array is actually of length length + 2. So it should be:

for (SBUInteger i = 0; i < length + 2; ++i) {
    fixedTypes[i] = SBBidiTypeNil;
}

To be pedantic, a condition that depends on uninitialized memory is undefined behavior, and UB is always a bug (which may or may not have consequences in some cases, but that's unpredictable on all toolchains/platforms).

I very much agree. This affects us too (us being the VVVVVV developers) as we are looking to integrate SheenBidi (see TerryCavanagh/VVVVVV#1093) but this error keeps coming up in Valgrind.

Can we send a pull request to fix this?

InfoTeddy added a commit to InfoTeddy/SheenBidi that referenced this issue Jan 10, 2024
This fixes an error of reading uninitialized memory, as reported by
Valgrind.

Fixes Tehreer#19.
@InfoTeddy InfoTeddy linked a pull request Jan 10, 2024 that will close this issue
InfoTeddy added a commit to InfoTeddy/SheenBidi that referenced this issue Jan 10, 2024
This fixes an error of reading uninitialized memory, as reported by
Valgrind.

Fixes Tehreer#19.
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 a pull request may close this issue.

4 participants