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
107 lines
4.2 KiB
C++
107 lines
4.2 KiB
C++
// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-not-null-terminated-result %t -- \
|
|
// RUN: -- -I %S/Inputs/not-null-terminated-result
|
|
|
|
#include "not-null-terminated-result-cxx.h"
|
|
|
|
#define __STDC_LIB_EXT1__ 1
|
|
#define __STDC_WANT_LIB_EXT1__ 1
|
|
|
|
void bad_wmemchr_1(wchar_t *position, const wchar_t *src) {
|
|
position = (wchar_t *)wmemchr(src, L'\0', wcslen(src));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: the length is too short to include the null terminator [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: position = wcschr(src, L'\0');
|
|
}
|
|
|
|
void good_wmemchr_1(wchar_t *pos, const wchar_t *src) {
|
|
pos = wcschr(src, L'\0');
|
|
}
|
|
|
|
void bad_wmemchr_2(wchar_t *position) {
|
|
position = (wchar_t *)wmemchr(L"foobar", L'\0', 6);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:51: warning: the length is too short to include the null terminator [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: position = wcschr(L"foobar", L'\0');
|
|
}
|
|
|
|
void good_wmemchr_2(wchar_t *pos) {
|
|
pos = wcschr(L"foobar", L'\0');
|
|
}
|
|
|
|
|
|
void bad_wmemmove(const wchar_t *src) {
|
|
wchar_t dest[13];
|
|
wmemmove(dest, src, wcslen(src));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemmove' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wchar_t dest[14];
|
|
// CHECK-FIXES-NEXT: wmemmove_s(dest, 14, src, wcslen(src) + 1);
|
|
}
|
|
|
|
void good_wmemmove(const wchar_t *src) {
|
|
wchar_t dst[14];
|
|
wmemmove_s(dst, 13, src, wcslen(src) + 1);
|
|
}
|
|
|
|
void bad_wmemmove_s(wchar_t *dest, const wchar_t *src) {
|
|
wmemmove_s(dest, 13, src, wcslen(src));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemmove_s' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wmemmove_s(dest, 13, src, wcslen(src) + 1);
|
|
}
|
|
|
|
void good_wmemmove_s_1(wchar_t *dest, const wchar_t *src) {
|
|
wmemmove_s(dest, 13, src, wcslen(src) + 1);
|
|
}
|
|
|
|
int bad_wcsncmp_1(wchar_t *wcs0, const wchar_t *wcs1) {
|
|
return wcsncmp(wcs0, wcs1, (wcslen(wcs0) + 1));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: return wcsncmp(wcs0, wcs1, (wcslen(wcs0)));
|
|
}
|
|
|
|
int bad_wcsncmp_2(wchar_t *wcs2, const wchar_t *wcs3) {
|
|
return wcsncmp(wcs2, wcs3, 1 + wcslen(wcs2));
|
|
// 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 wcsncmp(wcs2, wcs3, wcslen(wcs2));
|
|
}
|
|
|
|
int good_wcsncmp_1_2(wchar_t *wcs4, const wchar_t *wcs5) {
|
|
return wcsncmp(wcs4, wcs5, wcslen(wcs4));
|
|
}
|
|
|
|
int bad_wcsncmp_3(wchar_t *wcs6) {
|
|
return wcsncmp(wcs6, L"string", 7);
|
|
// 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 wcsncmp(wcs6, L"string", 6);
|
|
}
|
|
|
|
int good_wcsncmp_3(wchar_t *wcs7) {
|
|
return wcsncmp(wcs7, L"string", 6);
|
|
}
|
|
|
|
void bad_wcsxfrm_1(const wchar_t *long_source_name) {
|
|
wchar_t long_destination_array_name[13];
|
|
wcsxfrm(long_destination_array_name, long_source_name,
|
|
wcslen(long_source_name));
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: the result from calling 'wcsxfrm' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wchar_t long_destination_array_name[14];
|
|
// CHECK-FIXES-NEXT: wcsxfrm(long_destination_array_name, long_source_name,
|
|
// CHECK-FIXES-NEXT: wcslen(long_source_name) + 1);
|
|
}
|
|
|
|
void good_wcsxfrm_1(const wchar_t *long_source_name) {
|
|
wchar_t long_destination_array_name[14];
|
|
wcsxfrm(long_destination_array_name, long_source_name,
|
|
wcslen(long_source_name) + 1);
|
|
}
|
|
|
|
void bad_wcsxfrm_2() {
|
|
wchar_t long_destination_array_name1[16];
|
|
wcsxfrm(long_destination_array_name1, L"long_source_name", 16);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wcsxfrm' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wchar_t long_destination_array_name1[17];
|
|
// CHECK-FIXES: wcsxfrm(long_destination_array_name1, L"long_source_name", 17);
|
|
}
|
|
|
|
void good_wcsxfrm_2() {
|
|
wchar_t long_destination_array_name2[17];
|
|
wcsxfrm(long_destination_array_name2, L"long_source_name", 17);
|
|
}
|