Project

General

Profile

Actions

Bug #12283

closed

Fix for Fix for 12006 causes C++ exception

Added by Bruce MacDonald about 1 year ago. Updated 3 months ago.

Status:
Closed
Priority:
High
Target version:
Start date:
12/22/2023
Due date:
% Done:

100%

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 about 1 year 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 12 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 12 months ago

  • Target version set to 4.11.0
Actions #4

Updated by Matthias Van Ceulebroeck 12 months ago

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

Updated by Bruce MacDonald 12 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 #6

Updated by Romain Mardulyn 4 months ago

  • Assignee set to Romain Mardulyn
Actions #7

Updated by Matthias Van Ceulebroeck 3 months ago

  • Status changed from Review to Implemented @Emweb
  • Assignee changed from Romain Mardulyn to Matthias Van Ceulebroeck
  • % Done changed from 0 to 100
Actions #8

Updated by Matthias Van Ceulebroeck 3 months ago

  • Status changed from Implemented @Emweb to Closed
Actions

Also available in: Atom PDF