Project

General

Profile

Actions

Bug #12283

open

Fix for Fix for 12006 causes C++ exception

Added by Bruce MacDonald 4 months ago. Updated 4 months ago.

Status:
Review
Priority:
High
Assignee:
-
Target version:
Start date:
12/22/2023
Due date:
% Done:

0%

Estimated time:

Description

This code fragment from DomElement.C barfs on the call to back() if the jsCode string is empty. This happened to me when I refreshed a WCartesianChart by calling reset() on its model.

void DomElement::callJavaScript(const std::string& jsCode,
bool evenWhenDeleted)
{
++numManipulations_;
// Bug #12006: For safety always append semicolon
std::string terminatedJsCode = jsCode;
if (jsCode.back() != ';') {
terminatedJsCode += ";";
}
if (!evenWhenDeleted)
javaScript_ << terminatedJsCode << '\n';
else
javaScriptEvenWhenDeleted_ += terminatedJsCode;
}

my fix which solves my problem:

void DomElement::callJavaScript(const std::string& jsCode,
bool evenWhenDeleted)
{
++numManipulations_;
// Bug #12006: For safety always append semicolon
if (jsCode.empty())
return;
std::string terminatedJsCode = jsCode;
if (jsCode.back() != ';') {
terminatedJsCode += ";";
}
if (!evenWhenDeleted)
javaScript_ << terminatedJsCode << '\n';
else
javaScriptEvenWhenDeleted_ += terminatedJsCode;
}

Actions #1

Updated by Bruce MacDonald 4 months ago

... sorry about crappy formatting in my initial report


void DomElement::callJavaScript(const std::string& jsCode,
bool evenWhenDeleted)
{
  ++numManipulations_;
  // Fix for #12283
  if (jsCode.empty())
    return;
  // Bug #12006: For safety always append semicolon
  std::string terminatedJsCode = jsCode;
  if (jsCode.back() != ';') {
    terminatedJsCode += ";";
  }
  if (!evenWhenDeleted)
    javaScript_ << terminatedJsCode << '\n';
  else
    javaScriptEvenWhenDeleted_ += terminatedJsCode;
}
Actions #2

Updated by Matthias Van Ceulebroeck 4 months ago

  • Status changed from New to InProgress
  • Assignee set to Matthias Van Ceulebroeck

No worries. Thanks for noticing this oversight.

Actions #3

Updated by Matthias Van Ceulebroeck 4 months ago

  • Target version set to 4.11.0
Actions #4

Updated by Matthias Van Ceulebroeck 4 months ago

  • Status changed from InProgress to Review
  • Assignee deleted (Matthias Van Ceulebroeck)
Actions #5

Updated by Bruce MacDonald 4 months ago

Thanks Matthias! FYI, I actually implemented a very slightly different change which doesn't increment numManipulations_ and so far has worked fine for my use cases:

void DomElement::callJavaScript(const std::string& jsCode,
                                bool evenWhenDeleted)
{
  // Bug #12283: Ignore empty jsCode (otherwise jsCode.back() throws)
  if (jsCode.empty())
    return;
  ++numManipulations_;
  // Bug #12006: For safety always append semicolon
  std::string terminatedJsCode = jsCode;
  if (jsCode.back() != ';') {
    terminatedJsCode += ";";
  }
  if (!evenWhenDeleted)
    javaScript_ << terminatedJsCode << '\n';
  else
    javaScriptEvenWhenDeleted_ += terminatedJsCode;
}
Actions

Also available in: Atom PDF