On 3/20/2026 5:12 AM, Moritz Wenk wrote:
Is this a bug in QsciScintilla::annotation() (from qsciscintilla.cpp in version 
2.14.1) ? The variable ?buf? is never initialized with anything.

// Get the annotation for a line, if any.
QString QsciScintilla::annotation(int line) const
{
     int size = SendScintilla(SCI_ANNOTATIONGETTEXT, line, (const char *)0);
     char *buf = new char[size + 1];

     QString qs = bytesAsText(buf, size);
     delete[] buf;

     return qs;
}

I think you need some sleep my friend. Not putting you down, I get tired too. 😴In an allergy/sinus fog while writing this. 😵

char *buf = new char[size + 1];

new char[size + 1] allocates a contiguous byte buffer and returns a pointer to it. (Assuming you are on a little computer that uses 8-bit bytes as character arrays. On a Unisys mainframe with 36-bit words the discussion would be more complicated.

The pointer variable "buf" then gets assigned the pointer value returned by the new operation. This initializes it.

Unless compiled in debug mode, the new operation does not initialize. The allocated memory contains garbage. Almost nobody does it, but C++ 03 added () to initialize allocations.

https://en.wikipedia.org/wiki/C%2B%2B03

new char[size + 1]();

Would allocate a character array that was nulled out. It will do the same for any array created via new. It is more efficient than

new char[size + 1]{};

I can't find it now, sinus fog, but almost every Assembly language I've ever worked with has an instruction to zero fill a block. Some CISC machines allow you to allocate a zero filled block all in one instruction. The () notation typically uses that. The list notation {} typically has to use a loop.

The specialized Assembly language instructions got added to processors in the late 1960s-early-1970s so COBOL compilers could MOVE ZEROS, MOVE SPACES, and MOVE HIGH-VALUES to blocks of memory efficiently.

https://www.ibm.com/docs/en/cobol-zos/6.3.0?topic=literals-figurative-constants

Every native compiled language to exist since then has made use of these instructions under the hood.

Don't feel bad. I've been in IT 40 years now. Probably written over a million lines of C++. I've never used the () initializer. Never encountered code that did.

--
Roland Hughes, President
Logikal Solutions
(630)-205-1593  (cell)
https://theminimumyouneedtoknow.com
https://infiniteexposure.net
https://johnsmith-book.com

Reply via email to