Deleaker detects resource leaks in StackOverflow answer

Recently, I need to capture the mouse cursor in my homebrew screen capture application, so my search sent me to StackOverflow’s Capture screen shot with mouse cursor. Out of curiosity, I ran Deleaker on it and it finds 2 HBITMAP leaks with every capture. My application captures mouse cursor 30 times per second, so theContinue reading “Deleaker detects resource leaks in StackOverflow answer”

Anti-Pattern: Enum as Array Index with No Bound Check

Recently, I encountered program crashes because of unscoped enum as array index pattern once in the workplace and another in an open source library where I added another item in the enum. Evidently, this anti-pattern is very popular among C++ developers. Open source code using Enum as Array Index pattern without bound check in itsContinue reading “Anti-Pattern: Enum as Array Index with No Bound Check”

Put sleep() to make more money from HFT. And Lock-free vs Block-free

“Isn’t April Fools over?” the very first thought running through your mind after glancing at the title. Rest assured, this is not a trolling post to make a fool out of you. This year’s April Fool post is here, in case you missed the once-in-a-lifetime C++ joke of its kind. This article is about slowingContinue reading “Put sleep() to make more money from HFT. And Lock-free vs Block-free”

C++23: -> and :: to be replaced by . operator

In the biggest change to C++ syntax, -> and :: operators are to be replaced by . operator in the upcoming C++23 AF00L proposal. The rationale behind this proposal is there can be no confusion (as to which operator to use). The :: operator is not only used in scope resolution and also as class-to-static_member.Continue reading “C++23: -> and :: to be replaced by . operator”

Modernizing Raytracing In A Weekend

Ray Tracing In A Weekend Repo My Modernized Ray Tracing In A Weekend Repo The improvements I made to the original code: Convert all raw allocation to shared_ptr to prevent memory leaks. Replace non-reentrant rand() with a copy of C++11 random number generator in every thread using thread_local to avoid sharing and locking. Replace theContinue reading “Modernizing Raytracing In A Weekend”

CreateCertificateContext Failed

CertCreateCertificateContext failure can be fixed with first exporting the certificate to DER Encoded Binary X.509 (cer file) manually. std::vector<BYTE> vec; PCCERT_CONTEXT pCertContext = NULL; if (pCertContext = ::CertCreateCertificateContext( PKCS_7_ASN_ENCODING | X509_ASN_ENCODING,, vec.size())) { std::cout << “Success!\n”; } else { std::cout << “Failure!\n”; } If one want to forgo the manual export option, CryptQueryObject canContinue reading “CreateCertificateContext Failed”

Avoid Default Clause in Switch Case for Enum

Do not define a default clause for enum in switch statement! Say in future, if another fruit type is added to the enum, default clause shall cause the C++ compiler not to warn you that you have not handled the case for the new fruit. enum class Fruit { Apple, Orange }; Fruit fruit =Continue reading “Avoid Default Clause in Switch Case for Enum”

Private Inheritance

In private inheritance, the base class public access members are still public access in the derived class. Therefore the derived class still can call the base class functions and access its public data. But the user who instantiates the derived class, cannot access the public member of the base class, hence private inheritance. Public inheritanceContinue reading “Private Inheritance”

Digitally Signing Without Worrying About Cert Expiry

If you want your executable’s signature to be still valid after certificate validity period, you have to digitally sign it with a timestamp from one of the timestamp websites with /tr switch before its expiry. In my case, I choose This command is for Windows only. signtool.exe sign /tr /f Cert.pfx /p passwordContinue reading “Digitally Signing Without Worrying About Cert Expiry”