Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change path variables to std::string variables #21

Open
nilssass opened this issue Jun 24, 2024 · 0 comments
Open

Change path variables to std::string variables #21

nilssass opened this issue Jun 24, 2024 · 0 comments
Assignees

Comments

@nilssass
Copy link
Collaborator

In params.h and params.cpp the freezeout path sSurface and the output directory sSpectraDir are both stored as C style char strings with a fixed number of characters. This may lead to buffer overflow.

It is safer to swich to the more C++ style std::string class for both paths. Then the calls in params.cpp void readRarams(char* filename) need to be adjusted accordingly to something like:

#include "params.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdexcept>

namespace params {

std::string sSurface = "unset";
std::string sSpectraDir = "unset";
std::string sVorticity = "unset";
bool weakContribution = false;
bool rescatter = false;
bool shear = false;
bool bulk = false;
// double Temp = 0.0, mu_b = 0.0, mu_q = 0.0, mu_s = 0.0;
int NEVENTS = 0;
double NBINS = 0.0, QMAX = 0.0;
double dx = 0.0, dy = 0.0, deta = 0.0;
double ecrit = 0.0, cs2 = 0.0, ratio_pressure_energydensity = 0.0;
bool is_spin_sampling_on = false;

void readParams(const std::string& filename) {
    std::ifstream fin(filename);
    if (!fin.is_open()) {
        std::cerr << "cannot open parameters file " << filename << std::endl;
        exit(1);
    }

    std::string line;
    while (std::getline(fin, line)) {
        std::istringstream sline(line);
        std::string parName, parValue;
        sline >> parName >> parValue;

        if (parName == "surface") sSurface = parValue;
        else if (parName == "dbeta") sVorticity = parValue;
        else if (parName == "spectra_dir") sSpectraDir = parValue;
        else if (parName == "Nbins") NBINS = std::stoi(parValue);
        else if (parName == "q_max") QMAX = std::stof(parValue);
        else if (parName == "number_of_events") NEVENTS = std::stoi(parValue);
        else if (parName == "rescatter") rescatter = std::stoi(parValue);
        else if (parName == "weakContribution") weakContribution = std::stoi(parValue);
        else if (parName == "shear") shear = std::stoi(parValue);
        else if (parName == "bulk") bulk = std::stoi(parValue);
        else if (parName == "ecrit") ecrit = std::stof(parValue);
        else if (parName == "cs2") cs2 = std::stof(parValue);
        else if (parName == "ratio_pressure_energydensity") ratio_pressure_energydensity = std::stof(parValue);
        else if (parName == "sample_spin") is_spin_sampling_on = std::stoi(parValue);
        else if (parName[0] == '!') std::cout << "CCC " << sline.str() << std::endl;
        else std::cout << "UUU " << sline.str() << std::endl;
    }

    deta = 0.05;
    dx = dy = 0.0;  // TODO!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants