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
85 lines
3.3 KiB
C
85 lines
3.3 KiB
C
// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
|
|
// RUN: -- -I %S/Inputs/not-null-terminated-result
|
|
|
|
#include "not-null-terminated-result-c.h"
|
|
|
|
void path_sensitive_unknown_length(char *position, const char *src) {
|
|
int length;
|
|
length = strlen(src);
|
|
position = (char *)memchr(src, '\0', length);
|
|
}
|
|
|
|
void bad_memchr(char *position, const char *src) {
|
|
int length = strlen(src);
|
|
position = (char *)memchr(src, '\0', length);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: the length is too short to include the null terminator [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: position = strchr(src, '\0');
|
|
}
|
|
|
|
void good_memchr(char *pos, const char *src) {
|
|
pos = strchr(src, '\0');
|
|
}
|
|
|
|
void bad_strerror_s(int errno) {
|
|
char dest[13];
|
|
int length = strlen(strerror(errno));
|
|
strerror_s(dest, length, errno);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'strerror_s' is not null-terminated and missing the last character of the error message [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: char dest[14];
|
|
// CHECK-FIXES-NEXT: int length = strlen(strerror(errno));
|
|
// CHECK-FIXES-NEXT: strerror_s(dest, length + 1, errno);
|
|
}
|
|
|
|
void good_strerror_s(int errno) {
|
|
char dst[14];
|
|
int length = strlen(strerror(errno));
|
|
strerror_s(dst, length + 1, errno);
|
|
}
|
|
|
|
int bad_strncmp_1(char *str1, const char *str2) {
|
|
int length = strlen(str1) + 1;
|
|
return strncmp(str1, str2, length);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: return strncmp(str1, str2, length - 1);
|
|
}
|
|
|
|
int good_strncmp_1(char *str1, const char *str2) {
|
|
int length = strlen(str1) + 1;
|
|
return strncmp(str1, str2, length - 1);
|
|
}
|
|
|
|
int bad_strncmp_2(char *str2) {
|
|
return strncmp(str2, "foobar", (strlen("foobar") + 1));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: return strncmp(str2, "foobar", (strlen("foobar")));
|
|
}
|
|
|
|
int bad_strncmp_3(char *str3) {
|
|
return strncmp(str3, "foobar", 1 + strlen("foobar"));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: return strncmp(str3, "foobar", strlen("foobar"));
|
|
}
|
|
|
|
int good_strncmp_2_3(char *str) {
|
|
return strncmp(str, "foobar", strlen("foobar"));
|
|
}
|
|
|
|
void bad_strxfrm(const char *long_source_name) {
|
|
char long_destination_name[13];
|
|
int very_long_length_definition_name = strlen(long_source_name);
|
|
strxfrm(long_destination_name, long_source_name,
|
|
very_long_length_definition_name);
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: the result from calling 'strxfrm' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: char long_destination_name[14];
|
|
// CHECK-FIXES-NEXT: int very_long_length_definition_name = strlen(long_source_name);
|
|
// CHECK-FIXES-NEXT: strxfrm(long_destination_name, long_source_name,
|
|
// CHECK-FIXES-NEXT: very_long_length_definition_name + 1);
|
|
}
|
|
|
|
void good_strxfrm(const char *long_source_name) {
|
|
char long_destination_name[14];
|
|
int very_long_length_definition_name = strlen(long_source_name);
|
|
strxfrm(long_destination_name, long_source_name,
|
|
very_long_length_definition_name + 1);
|
|
}
|