Skip to content

Commit 55396eb

Browse files
committed
chore: add some tests
1 parent 352e824 commit 55396eb

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

test/functional/run/use_unitialized_var.glu

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,37 +119,52 @@ func createStringFromPointer(s: *Char, length: Int, allocated: Bool) -> String {
119119
return { s, length, allocated };
120120
}
121121

122-
public func stringTrim(s: String) -> String {
123-
if (s.length == 0) {
124-
return s;
122+
func ddsdadasfasf(machin: Bool) -> Void {
123+
var x : Int;
124+
var y : Int = 0;
125+
126+
if (machin) {
127+
x = 0;
125128
}
126129

127-
var start: Int = 0;
128-
var end: Int = s.length - 1;
130+
while (machin) {
131+
y = y + 1;
129132

130-
// Find first non-space character
131-
while (start <= end && (s.data[start] == " " || s.data[start] == "\n" || s.data[start] == "\t")) {
132-
start = start + 1;
133+
if (y > 10) {
134+
y = 10;
135+
break;
136+
}
133137
}
138+
// CHECK: use_unitialized_var.glu:139:11: error: Load from uninitialized memory location
139+
print(x);
140+
}
134141

135-
// Find last non-space character
136-
while (end >= start && (s.data[end] == " " || s.data[end] == "\n" || s.data[end] == "\t")) {
137-
end = end - 1;
138-
}
142+
func ddsdadasdadasfasf(machin: Bool) -> Void {
143+
var x : Int;
144+
var y : Int = 0;
145+
var z : Int;
139146

140-
// Create trimmed string
141-
let newLength: Int = end - start + 1;
142-
if (newLength <= 0) {
143-
return createStringFromPointer(null, 0, false);
147+
if (machin) {
148+
x = 0;
144149
}
145150

146-
var str: *Char = allocate(newLength);
147-
memcpy(str, &s.data[start], newLength);
148-
return createStringFromPointer(str, newLength, true);
149-
}
151+
while (machin) {
152+
y = y + 1;
150153

151-
public func +(lhs: String, rhs: String) -> Void {
152-
var result: *Char = allocate(lhs.length + rhs.length + 1);
154+
if (y > 10) {
155+
y = 10;
156+
break;
157+
}
158+
// CHECK: use_unitialized_var.glu:159:15: error: Load from uninitialized memory location
159+
print(z);
153160

154-
memcpy(&result[lhs.length], rhs.data, rhs.length);
161+
// CHECK: use_unitialized_var.glu:162:13: error: Load from uninitialized memory location
162+
if (z == 1) {
163+
z = 0;
164+
}
165+
}
166+
// CHECK: use_unitialized_var.glu:167:11: error: Load from uninitialized memory location
167+
print(x);
168+
// CHECK: use_unitialized_var.glu:169:11: error: Load from uninitialized memory location
169+
print(z);
155170
}

0 commit comments

Comments
 (0)