Skip to content

Commit dd2a4ff

Browse files
committed
fix(build): add iterator guard and overload dispatch for read path
1 parent aed40e3 commit dd2a4ff

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

flagcx/core/reg_pool.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ flagcxResult_t flagcxRegPool::registerBuffer(void *comm, void *data,
188188
// Update regPool key to match new beginAddr
189189
auto &globalPool = regPool[GLOBAL_POOL_KEY];
190190
auto nodeIt = globalPool.find(oldBegin);
191+
if (nodeIt == globalPool.end()) {
192+
WARN("registerBuffer: regPool key mismatch for oldBegin");
193+
return flagcxInternalError;
194+
}
191195
std::unique_ptr<flagcxRegItem> tmp = std::move(nodeIt->second);
192196
globalPool.erase(nodeIt);
193197
globalPool.emplace(beginAddr, std::move(tmp));

flagcx/runner/include/c2c_ir.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@ void serializeFunc2DVector(FILE *file, size_t chunksize,
147147
fprintf(file, "%*s</%s>\n", indent, "", tagName);
148148
}
149149

150+
// Overloaded dispatch helpers for readFunc2DVector (C++11-compatible
151+
// alternative to if constexpr)
152+
inline void readFuncStep(FILE *file, size_t chunksize, const char *line,
153+
std::vector<flagcxC2cHomoFunc> &step) {
154+
if (strstr(line, "<HomoFunc>"))
155+
step.emplace_back(file, chunksize);
156+
}
157+
158+
inline void readFuncStep(FILE *file, size_t chunksize, const char *line,
159+
std::vector<flagcxC2cHeteroFunc> &step) {
160+
if (strstr(line, "<HeteroFunc>"))
161+
step.emplace_back(file, chunksize);
162+
}
163+
150164
template <typename T>
151165
std::vector<std::vector<T>> readFunc2DVector(FILE *file, size_t chunksize,
152166
const char *tagName) {
@@ -169,13 +183,7 @@ std::vector<std::vector<T>> readFunc2DVector(FILE *file, size_t chunksize,
169183
while (fgets(line, sizeof(line), file)) {
170184
if (strstr(line, "</Step>"))
171185
break;
172-
if (std::is_same<T, flagcxC2cHomoFunc>::value) {
173-
if (strstr(line, "<HomoFunc>"))
174-
step.emplace_back(file, chunksize);
175-
} else if (std::is_same<T, flagcxC2cHeteroFunc>::value) {
176-
if (strstr(line, "<HeteroFunc>"))
177-
step.emplace_back(file, chunksize);
178-
}
186+
readFuncStep(file, chunksize, line, step);
179187
}
180188
result.push_back(step);
181189
}

0 commit comments

Comments
 (0)