Menu

#579 TCharFormat constructor sets cbSize incorrectly

8
pending
Internal (140)
1
2024-10-05
2024-10-04
No

The constructor TCharFormat (ulong mask) sets cbSize = sizeof(::CHARFORMAT). It should use the base class CHARFORMAT2 here.

This issue was silently fixed on the trunk in [r5853] as part of other TCharFormat improvements.

Note that this bug may lead to issues with features of the TRichEdit control not working as they should.

Reported by @damonregister [discussion:d7e28a3b2e].

Related

Commit: [r5853]
Discussion: d7e28a3b2e
Discussion: TRichEdit background color OWL 7.0 vs 7.1
Wiki: OWLNext_Roadmap_and_Prereleases

Discussion

  • Damon Register

    Damon Register - 2024-10-04

    Perhaps I didn't express well in my post to the forum. The constructor TCharFormat correctly sets cbSize to sizeof(CHARFORMAT2) while the GetCharFormat does not set the size correctly.

    I just re-read your post and realized I forgot about the 2 overloaded constructors. The one works while guess the other doesn't. Thanks for submitting this bug.

     

    Last edit: Vidar Hasfjord 2024-10-04
  • Vidar Hasfjord

    Vidar Hasfjord - 2024-10-04

    @damonregister wrote:

    I just re-read your post and realized I forgot about the 2 overloaded constructors. The one works while guess the other doesn't.

    Yes, exactly! As I wrote in [discussion:d7e28a3b2e], the constructor TCharFormat (ulong mask) sets cbSize = sizeof(::CHARFORMAT), which is a bug, while the (deprecated) constructor TCharFormat (const TRichEdit& edit, bool selection, ulong mask) correctly sets cbSize = sizeof(CHARFORMAT2).

    And note that TRichEditor::GetCharFormat (TCharFormat & cf, bool selection) does not set the cbSize field of the passed TCharFormat instance, but relies on how it has been initialised.

    Workaround

    #include <owl/richedit.h>
    using namespace owl;
    
    //
    // Function to retrieve character format.
    // Ensures TCharFormat::cbSize is set correctly.
    //
    auto GetCharacterFormat(TRichEdit& richEdit, bool selection) -> TCharFormat
    {
      auto cf = TCharFormat{};
      cf.cbSize = sizeof(CHARFORMAT2);
      richEdit.GetCharFormat(cf, selection);
      return cf;
    }
    
    void ExampleUsage(TRichEdit& richEdit)
    {
      const auto cf = GetCharacterFormat(richEdit, true); // true for selection, false for default.
    
      // Now cf contains the character format information.
      // You can access cf members here.
    }
    

    In version 8, you'll be able to simply use our new functional-style overload:

    const auto cf = richEdit.GetCharFormat(true); // true for selection, false for default.
    

    Thanks for submitting this bug.

    Thanks for reporting the issue and identifying the bug!

     

    Related

    Discussion: d7e28a3b2e


    Last edit: Vidar Hasfjord 2024-10-05
  • Vidar Hasfjord

    Vidar Hasfjord - 2024-10-05

    Note that this bug has been present since 6.04, and that the buggy implementation of the constructor TCharFormat (ulong mask) was inlined in "richedit.h" [r5] until it was corrected and moved to "richedit.cpp (sourceforge.net)" [r5853] on the trunk (version 8).

    Since the bug is inlined, and the fix hence requires a full recompile of all client code (and hence isn't ABI compatible), we cannot merge this fix into any of our LTS releases (6.30, 6.36 and 6.44). Nor can we merge it into 7.0, although we can of course bump the current release version to 7.1, if there is demand for an immediate fix. For now, I have set the milestone to version 8, leaving users of older versions to apply the workaround mentioned earlier.

     

    Related

    Commit: [r5]
    Commit: [r5853]


    Last edit: Vidar Hasfjord 2024-10-05

Log in to post a comment.

MongoDB Logo MongoDB