Skip to content

Commit

Permalink
Merge pull request #109 from FRIBDAQ/rfoxkendo/issue90
Browse files Browse the repository at this point in the history
Issue #90 - Parsing mask gates was not correct. This pull fixes that issue.
  • Loading branch information
rfoxkendo authored Mar 8, 2024
2 parents f7dc06b + be6e59b commit 562c98b
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions main/Core/GateCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ static const char* Copyright = "(C) Copyright Michigan State University 2008, Al
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <string>
#ifdef HAVE_STD_NAMESPACE
Expand Down Expand Up @@ -420,20 +421,32 @@ CGateCommand::NewGate(CTCLInterpreter& rInterp, CTCLResult& rResult,

if(Item.nParameters == 1) {
if ((string(pType) == string("em")) ||
(string(pType) == string("am")) ||
(string(pType) == string("nm")))
{
long Compare ;
sscanf(PointString[0].c_str(), "%lx", &Compare);
pGate = api.CreateGate(Item.eGateType, Parameters, Compare);
if(rPackage.AddGate(rResult, string(pName), pGate)) {
return TCL_OK;
}
else {
return TCL_ERROR;
(string(pType) == string("am")) ||
(string(pType) == string("nm"))) {
unsigned long Compare;
char* endPtr(nullptr);

// Issue 90: was using sscanf which forced interpretation
// of the string to hex regardless of how it was passed.
// strtoul is better since with base =0 it uses any radix
// elements to decide if the string is hex, or even octal.
//
Compare = strtoul(PointString[0].c_str(), &endPtr, 0);
if (endPtr == PointString[0].c_str()) {
// Bad conversion:

rInterp.setResult("Invalid mask value");
return TCL_ERROR;
}
pGate = api.CreateGate(Item.eGateType, Parameters, Compare);
if(rPackage.AddGate(rResult, string(pName), pGate)) {
return TCL_OK;
}
else {
return TCL_ERROR;
}
assert(0);
}
assert(0);
}
else {
for(UInt_t npoint = 0; npoint < PointString.size(); npoint++) {
Float_t x;
Expand Down

0 comments on commit 562c98b

Please sign in to comment.