Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 07be921

Browse files
authored
Replace report_name with report_path (#126)
- replace MAX_REPORT_PATH_LEN with MAX_FILEPATH_LEN - fixes segfault with long filepath
1 parent e10e0b5 commit 07be921

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

coreneuron/utils/reports/nrnreport.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ class ReportEvent : public DiscreteEvent {
6464
private:
6565
double dt;
6666
double step;
67-
char report_name[MAX_REPORT_NAME_LEN];
67+
char report_path[MAX_FILEPATH_LEN];
6868
std::vector<int> gids_to_report;
6969
double tstart;
7070

7171
public:
7272
ReportEvent(double dt, double tstart, VarsToReport& filtered_gids, const char* name)
7373
: dt(dt), tstart(tstart) {
74-
strcpy(report_name, name);
74+
strcpy(report_path, name);
7575
VarsToReport::iterator it;
7676
nrn_assert(filtered_gids.size());
7777
step = tstart / dt;
@@ -88,7 +88,7 @@ class ReportEvent : public DiscreteEvent {
8888
#pragma omp critical
8989
{
9090
// each thread needs to know its own step
91-
records_nrec(step, gids_to_report.size(), &gids_to_report[0], report_name);
91+
records_nrec(step, gids_to_report.size(), &gids_to_report[0], report_path);
9292
send(t + dt, nc, nt);
9393
step++;
9494
}

coreneuron/utils/reports/nrnreport.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
#include <string>
4040
#include <vector>
4141
#include <set>
42+
4243
#define MAX_REPORT_NAME_LEN 256
43-
#define MAX_REPORT_PATH_LEN 512
44+
#define MAX_FILEPATH_LEN 4096
4445

4546
namespace coreneuron {
4647
// name of the variable in mod file that is used to indicate which synapse
@@ -54,7 +55,7 @@ enum ReportType { SomaReport, CompartmentReport, SynapseReport };
5455

5556
struct ReportConfiguration {
5657
char name[MAX_REPORT_NAME_LEN]; // name of the report
57-
char output_path[MAX_REPORT_PATH_LEN]; // full path of the report
58+
char output_path[MAX_FILEPATH_LEN]; // full path of the report
5859
char target_name[MAX_REPORT_NAME_LEN]; // target of the report
5960
char mech_name[MAX_REPORT_NAME_LEN]; // mechanism name
6061
char var_name[MAX_REPORT_NAME_LEN]; // variable name

coreneuron/utils/reports/report_configuration_parser.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
#include <vector>
3737
#include <string.h>
3838

39-
#define MAX_LINE_LENGTH 4096
40-
4139
namespace coreneuron {
4240

4341
/*
@@ -63,7 +61,7 @@ std::vector<ReportConfiguration> create_report_configurations(const char* conf_f
6361
std::vector<ReportConfiguration> reports;
6462
int num_reports = 0;
6563
char report_on[MAX_REPORT_NAME_LEN] = "";
66-
char raw_line[MAX_LINE_LENGTH] = "";
64+
char raw_line[MAX_FILEPATH_LEN] = "";
6765
int is_soma;
6866
int* gids;
6967

@@ -74,14 +72,14 @@ std::vector<ReportConfiguration> create_report_configurations(const char* conf_f
7472
abort();
7573
}
7674

77-
fgets(raw_line, MAX_LINE_LENGTH, fp);
75+
fgets(raw_line, MAX_FILEPATH_LEN, fp);
7876
sscanf(raw_line, "%d\n", &num_reports);
7977
for (int i = 0; i < num_reports; i++) {
8078
reports.push_back(ReportConfiguration());
8179
ReportConfiguration& report = reports[reports.size() - 1];
8280
// mechansim id registered in coreneuron
8381
report.mech_id = -1;
84-
fgets(raw_line, MAX_LINE_LENGTH, fp);
82+
fgets(raw_line, MAX_FILEPATH_LEN, fp);
8583
sscanf(raw_line, "\n%s %s %s %s %s %s %d %lf %lf %lf %d\n", report.name, report.target_name,
8684
report.type_str, report_on, report.unit, report.format, &is_soma, &report.report_dt,
8785
&report.start, &report.stop, &report.num_gids);
@@ -108,7 +106,7 @@ std::vector<ReportConfiguration> create_report_configurations(const char* conf_f
108106
gids = (int*)calloc(report.num_gids, sizeof(int));
109107
fread(gids, sizeof(int), report.num_gids, fp);
110108
// extra new line
111-
fgets(raw_line, MAX_LINE_LENGTH, fp);
109+
fgets(raw_line, MAX_FILEPATH_LEN, fp);
112110
for (int i = 0; i < report.num_gids; i++) {
113111
report.target.insert(gids[i]);
114112
}

0 commit comments

Comments
 (0)