by Yu Feng
Repair = Locate âź¶ Synthesize âź¶ Validate
int index_of(char*s,char c){
int i, n=strlen(s);
for(i=0;i<=n;i++){
if(s[i]==c) return i;
}
return -1;
}
// Original buggy code
return data.getValue();
// Template-based patch
if (data != null) {
return data.getValue();
} else {
return 0; // default value
}
// Buggy code with off-by-one error
for (int i = 0; i <= n; i++) {
array[i] = 0; // Crashes when i == n
}
// SemFix repair process:
// 1. Replace condition with hole: for(int i=0; ??; i++)
// 2. Extract expected behavior from tests
// 3. Synthesize condition: i < n
// Final repair:
for (int i = 0; i < n; i++) {
array[i] = 0; // Correct bound check
}
// Buggy code with potential division by zero
int compute(int a, int b) {
int result = 0;
if (a > 0)
result = 100 / b; // May crash when b = 0
return result;
}
// Angelix repair process:
// 1. Identifies b = 0 causes failure
// 2. Discovers guard condition needed
// 3. Synthesizes correct patch
// Final multi-location repair:
int compute(int a, int b) {
int result = 0;
if (a > 0 && b != 0) // Added condition
result = 100 / b;
return result;
}
// Bug: Missing null check
void process(String s) {
int len = s.length();
// ...
}
// Candidate patches ranked by ML:
// 1. if (s != null) {int len = s.length();}
// 2. int len = s == null ? 0 : s.length();
// 3. try {int len = s.length();} catch(...)
// Original implementation (with bug)
int sum(int arr[], int n) {
int total = 0;
// Bug: off-by-one error
for (int i = 0; i <= n; i++)
total += arr[i];
return total;
}
// Semantically equivalent repair
int sum(int arr[], int n) {
int total = 0;
// Fixed bound condition
for (int i = 0; i < n; i++)
total += arr[i];
return total;
}