CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
96 lines
2.3 KiB
C
96 lines
2.3 KiB
C
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,debug.ExprInspection -verify %s
|
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,alpha.unix,debug.ExprInspection -verify %s
|
|
|
|
#include "Inputs/system-header-simulator.h"
|
|
#include "Inputs/system-header-simulator-for-malloc.h"
|
|
|
|
void test_getline_null_buffer() {
|
|
FILE *F1 = tmpfile();
|
|
if (!F1)
|
|
return;
|
|
char *buffer = NULL;
|
|
size_t n = 0;
|
|
if (getline(&buffer, &n, F1) > 0) {
|
|
char c = buffer[0]; // ok
|
|
}
|
|
free(buffer);
|
|
fclose(F1);
|
|
}
|
|
|
|
void test_getline_malloc_buffer() {
|
|
FILE *F1 = tmpfile();
|
|
if (!F1)
|
|
return;
|
|
|
|
size_t n = 10;
|
|
char *buffer = malloc(n);
|
|
char *ptr = buffer;
|
|
|
|
ssize_t r = getdelim(&buffer, &n, '\r', F1);
|
|
// ptr may be dangling
|
|
free(ptr); // expected-warning {{Attempt to release already released memory}}
|
|
free(buffer); // ok
|
|
fclose(F1);
|
|
}
|
|
|
|
void test_getline_alloca() {
|
|
FILE *F1 = tmpfile();
|
|
if (!F1)
|
|
return;
|
|
size_t n = 10;
|
|
char *buffer = alloca(n);
|
|
getline(&buffer, &n, F1); // expected-warning {{Memory allocated by 'alloca()' should not be deallocated}}
|
|
fclose(F1);
|
|
}
|
|
|
|
void test_getline_invalid_ptr() {
|
|
FILE *F1 = tmpfile();
|
|
if (!F1)
|
|
return;
|
|
size_t n = 10;
|
|
char *buffer = (char*)test_getline_invalid_ptr;
|
|
getline(&buffer, &n, F1); // expected-warning {{Argument to 'getline()' is the address of the function 'test_getline_invalid_ptr', which is not memory allocated by 'malloc()'}}
|
|
fclose(F1);
|
|
}
|
|
|
|
void test_getline_leak() {
|
|
FILE *F1 = tmpfile();
|
|
if (!F1)
|
|
return;
|
|
|
|
char *buffer = NULL;
|
|
size_t n = 0;
|
|
ssize_t read;
|
|
|
|
while ((read = getline(&buffer, &n, F1)) != -1) {
|
|
printf("%s\n", buffer);
|
|
}
|
|
|
|
fclose(F1); // expected-warning {{Potential memory leak}}
|
|
}
|
|
|
|
void test_getline_stack() {
|
|
size_t n = 10;
|
|
char buffer[10];
|
|
char *ptr = buffer;
|
|
|
|
FILE *F1 = tmpfile();
|
|
if (!F1)
|
|
return;
|
|
|
|
getline(&ptr, &n, F1); // expected-warning {{Argument to 'getline()' is the address of the local variable 'buffer', which is not memory allocated by 'malloc()'}}
|
|
}
|
|
|
|
void test_getline_static() {
|
|
static size_t n = 10;
|
|
static char buffer[10];
|
|
char *ptr = buffer;
|
|
|
|
FILE *F1 = tmpfile();
|
|
if (!F1)
|
|
return;
|
|
|
|
getline(&ptr, &n, F1); // expected-warning {{Argument to 'getline()' is the address of the static variable 'buffer', which is not memory allocated by 'malloc()'}}
|
|
}
|