-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Open
Description
Issue: Potential Runtime Errors in Budget Shopping Calculator
Description
The budget shopping calculator has several potential runtime errors including possible segmentation faults, invalid memory access, and unhandled edge cases when processing input data.
Root Cause
- No input validation for empty input strings
- Potential out-of-bounds access in vector indexing
- No error handling for malformed input data
- Assumption that input will always be properly formatted
Affected Code
vector<string> split_string(string input_string) {
// Potential issues with empty strings:
while (input_string[input_string.length() - 1] == ' ') { // CRASH: access [-1] if empty
input_string.pop_back();
}
// ... rest of splitting logic
}
int main() {
// No validation before processing:
vector<string> bnm = split_string(bnm_temp); // Could crash if bnm_temp empty
int b = stoi(bnm[0]); // Could crash if bnm empty
int n = stoi(bnm[1]); // Could crash if bnm size < 2
int m = stoi(bnm[2]); // Could crash if bnm size < 3
// Similar issues with keyboards_temp_temp and drives_temp_temp
for (int keyboards_itr = 0; keyboards_itr < n; keyboards_itr++) {
int keyboards_item = stoi(keyboards_temp[keyboards_itr]); // Could crash
keyboards[keyboards_itr] = keyboards_item;
}
}Metadata
Metadata
Assignees
Labels
No labels