Windows Calc Source-Code: A Nightmare …

Windows Calc app is located on billions of computers, because it is sipped with Windows. Recently the source code of the program was released as Open Source on GitHub. Some people have inspected the program code, and came to the conclusion, that's a nightmare. Memory leaks, clipboard content goes to Microsoft server, calculation errors and more.


Advertising

Currently we can read about plans from Microsoft, that developers intend to integrate a graphics function display into the Windows 10 calc app. But it would be more important to clean up the source code of this program. 

(Source: Microsoft)

Blog reader Adrian has send me a link to this article – thanks for that. It's about the Windows app Calc, which is on board on all Windows systems. A few days ago the source code of this program was released as Open Source on Github (see MS releases Windows Calc app as Open Source on GitHub).

The PVS-Studio community took a look at the code and found something amazing. They used PVS-Studio to analyze the source code of all modules. Here are a few findings.

The following code fragment in the GitHub source code of the calc app immediately attracted the attention of the community.


Advertising

void TraceLogger::LogInvalidInputPasted(....)
{
  if (!GetTraceLoggingProviderEnabled()) return;

  LoggingFields fields{};
  fields.AddString(L"Mode", NavCategory::GetFriendlyName(mode)->Data());
  fields.AddString(L"Reason", reason);
  fields.AddString(L"PastedExpression", pastedExpression);
  fields.AddString(L"ProgrammerNumberBase", GetProgrammerType(...).c_str());
  fields.AddString(L"BitLengthType", GetProgrammerType(bitLengthType).c_str());
  LogTelemetryEvent(EVENT_NAME_INVALID_INPUT_PASTED, fields);
}

This function logs text from the clipboard and apparently sends it to the Microsoft server. The PVS Studio article tells me that the code contains more 'suspicious' places.

  • Wrong string comparison (V547, Calculator LocalizationSettings.h Zeile 180): An expression 'm_resolvedName == L«en-US»' within an if query always returns the value false.
  • Memory leak in program code (V773, CalcViewModel StandardCalculatorViewModel.cpp Zeile 529): A potential memory leak exists in the module, because a function is terminated without releasing the "temp" pointer.
  • Severe exception (V702, CalcManager CalcException.h Zeile 4):
  • Classes should always be derived from std::exception (and the like) as 'public' (no keyword was specified, so the compiler sets it to 'private' by default).
  • Missing Day in module (V719, CalcViewModel DateCalculator.cpp Zeile 279): The switch statement does not cover all values of the enumeration 'DateUnit.
  • Suspicious comparison of real numbers (V550, Calculator AspectRatioTrigger.cpp Zeile 80): The code contains a strange comparison of two real numbers (floating point values) of the type ratio == threshold. It is probably better to use a comparison with defined accuracy: fabs(A – B) < Epsilon.

At this point I will abort the listing. The article on habr.com contains a whole bunch of other such style blossoms in the program code. Well, mistakes can always happen – I know that too – although my days as a developer are over since 25 years. But the question already arises how things are with the code quality from Redmond. What's your opinion?


Cookies helps to fund this blog: Cookie settings
Advertising


##1

This entry was posted in Software and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *