You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
getline(&buffer, &n, file); // expected-warning {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
311
-
}
312
-
fclose(file);
313
-
free(buffer);
314
-
}
315
-
316
-
voidtest_getline_feof() {
317
-
FILE*file=fopen("file.txt", "r");
318
-
if (file==NULL) {
319
-
return;
320
-
}
321
-
322
-
size_tn=10;
323
-
char*buffer=malloc(n);
324
-
ssize_tread=fread(buffer, n, 1, file);
325
-
getline(&buffer, &n, file); // expected-warning {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}} \\
326
-
expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
if (line[0] =='\0') {} // expected-warning {{The left operand of '==' is a garbage value}}
404
+
405
+
free(line);
406
+
fclose(file);
407
+
}
408
+
409
+
voidgetline_after_eof() {
410
+
FILE*file=fopen("file.txt", "r");
411
+
if (file==NULL) {
412
+
return;
413
+
}
414
+
415
+
size_tn=10;
416
+
char*buffer=malloc(n);
417
+
ssize_tread=fread(buffer, n, 1, file);
418
+
if (!feof(file)) {
419
+
getline(&buffer, &n, file); // expected-warning {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
420
+
}
421
+
fclose(file);
422
+
free(buffer);
423
+
}
424
+
425
+
voidgetline_feof() {
426
+
FILE*file=fopen("file.txt", "r");
427
+
if (file==NULL) {
428
+
return;
429
+
}
430
+
431
+
size_tn=10;
432
+
char*buffer=malloc(n);
433
+
ssize_tread=fread(buffer, n, 1, file);
434
+
getline(&buffer, &n, file); // expected-warning {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}} \\
435
+
expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
0 commit comments