mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 09:02:08 +00:00
clean-up
This commit is contained in:
parent
e1856daf57
commit
7ff3e572a4
8 changed files with 3 additions and 610 deletions
|
|
@ -1,33 +0,0 @@
|
||||||
# Set breakpoint at main
|
|
||||||
b main
|
|
||||||
# Run the program
|
|
||||||
run
|
|
||||||
# Step through to see what happens
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
n
|
|
||||||
# Now we're in the loop - let's examine the students array
|
|
||||||
p num_students
|
|
||||||
p students[0]
|
|
||||||
p students[1]
|
|
||||||
p students[2]
|
|
||||||
# Continue to the crash
|
|
||||||
c
|
|
||||||
# When it crashes, show backtrace
|
|
||||||
bt
|
|
||||||
# Examine the frame
|
|
||||||
frame variable
|
|
||||||
# Look at what students[i] is when it crashes
|
|
||||||
p i
|
|
||||||
p students[i]
|
|
||||||
quit
|
|
||||||
479
out.html
479
out.html
File diff suppressed because one or more lines are too long
|
|
@ -11,6 +11,9 @@
|
||||||
{
|
{
|
||||||
"name": "mini-lit",
|
"name": "mini-lit",
|
||||||
"path": "../mini-lit"
|
"path": "../mini-lit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "../../agent-tools/browser-tools"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": {}
|
"settings": {}
|
||||||
|
|
|
||||||
BIN
test
BIN
test
Binary file not shown.
73
test.c
73
test.c
|
|
@ -1,73 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *name;
|
|
||||||
int age;
|
|
||||||
int *scores;
|
|
||||||
} Student;
|
|
||||||
|
|
||||||
Student* create_student(const char *name, int age, int num_scores) {
|
|
||||||
Student *s = malloc(sizeof(Student));
|
|
||||||
s->name = malloc(strlen(name)); // Bug 1: Missing +1 for null terminator
|
|
||||||
strcpy(s->name, name);
|
|
||||||
s->age = age;
|
|
||||||
s->scores = malloc(num_scores * sizeof(int));
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_student(Student *s, int num_scores) {
|
|
||||||
printf("Name: %s, Age: %d\n", s->name, s->age);
|
|
||||||
printf("Scores: ");
|
|
||||||
for (int i = 0; i <= num_scores; i++) { // Bug 2: Off-by-one error (should be <)
|
|
||||||
printf("%d ", s->scores[i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
double calculate_average(int *scores, int count) {
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
sum += scores[i];
|
|
||||||
}
|
|
||||||
return sum / count; // Bug 3: Integer division instead of floating point
|
|
||||||
}
|
|
||||||
|
|
||||||
void free_student(Student *s) {
|
|
||||||
free(s->name);
|
|
||||||
free(s->scores);
|
|
||||||
// Bug 4: Forgot to free(s) itself - memory leak
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int num_students = 3;
|
|
||||||
Student **students = malloc(num_students * sizeof(Student*));
|
|
||||||
|
|
||||||
students[0] = create_student("Alice", 20, 3);
|
|
||||||
students[0]->scores[0] = 85;
|
|
||||||
students[0]->scores[1] = 90;
|
|
||||||
students[0]->scores[2] = 88;
|
|
||||||
|
|
||||||
students[1] = create_student("Bob", 22, 3);
|
|
||||||
students[1]->scores[0] = 75;
|
|
||||||
students[1]->scores[1] = 80;
|
|
||||||
students[1]->scores[2] = 70;
|
|
||||||
|
|
||||||
students[2] = NULL; // Bug 5: Uninitialized student
|
|
||||||
|
|
||||||
for (int i = 0; i < num_students; i++) {
|
|
||||||
print_student(students[i], 3); // Will crash on NULL student
|
|
||||||
double avg = calculate_average(students[i]->scores, 3);
|
|
||||||
printf("Average: %.2f\n\n", avg);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < num_students; i++) {
|
|
||||||
if (students[i] != NULL) {
|
|
||||||
free_student(students[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(students);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
|
||||||
<string>English</string>
|
|
||||||
<key>CFBundleIdentifier</key>
|
|
||||||
<string>com.apple.xcode.dsym.test</string>
|
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
|
||||||
<string>6.0</string>
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>dSYM</string>
|
|
||||||
<key>CFBundleSignature</key>
|
|
||||||
<string>????</string>
|
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>1.0</string>
|
|
||||||
<key>CFBundleVersion</key>
|
|
||||||
<string>1</string>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
Binary file not shown.
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
triple: 'arm64-apple-darwin'
|
|
||||||
binary-path: test
|
|
||||||
relocations: []
|
|
||||||
...
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue