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
112 lines
4.2 KiB
C++
112 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
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// wmemcpy() - destination array tests
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void bad_wmemcpy_known_dest(const wchar_t *src) {
|
|
wchar_t dest01[13];
|
|
wmemcpy(dest01, src, wcslen(src));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemcpy' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wchar_t dest01[14];
|
|
// CHECK-FIXES-NEXT: wcscpy_s(dest01, src);
|
|
}
|
|
|
|
void good_wmemcpy_known_dest(const wchar_t *src) {
|
|
wchar_t dst01[14];
|
|
wcscpy_s(dst01, src);
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// wmemcpy() - length tests
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void bad_wmemcpy_full_source_length(const wchar_t *src) {
|
|
wchar_t dest20[13];
|
|
wmemcpy(dest20, src, wcslen(src));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemcpy' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wchar_t dest20[14];
|
|
// CHECK-FIXES-NEXT: wcscpy_s(dest20, src);
|
|
}
|
|
|
|
void good_wmemcpy_full_source_length(const wchar_t *src) {
|
|
wchar_t dst20[14];
|
|
wcscpy_s(dst20, src);
|
|
}
|
|
|
|
void bad_wmemcpy_partial_source_length(const wchar_t *src) {
|
|
wchar_t dest21[13];
|
|
wmemcpy(dest21, src, wcslen(src) - 1);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemcpy' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wchar_t dest21[14];
|
|
// CHECK-FIXES-NEXT: wcsncpy_s(dest21, src, wcslen(src) - 1);
|
|
}
|
|
|
|
void good_wmemcpy_partial_source_length(const wchar_t *src) {
|
|
wchar_t dst21[14];
|
|
wcsncpy_s(dst21, src, wcslen(src) - 1);
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// wmemcpy_s() - destination array tests
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void bad_wmemcpy_s_unknown_dest(wchar_t *dest40, const wchar_t *src) {
|
|
wmemcpy_s(dest40, 13, src, wcslen(src));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemcpy_s' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wcscpy_s(dest40, 13, src);
|
|
}
|
|
|
|
void good_wmemcpy_s_unknown_dest(wchar_t *dst40, const wchar_t *src) {
|
|
wcscpy_s(dst40, 13, src);
|
|
}
|
|
|
|
void bad_wmemcpy_s_known_dest(const wchar_t *src) {
|
|
wchar_t dest41[13];
|
|
wmemcpy_s(dest41, 13, src, wcslen(src));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemcpy_s' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wchar_t dest41[14];
|
|
// CHECK-FIXES-NEXT: wcscpy_s(dest41, src);
|
|
}
|
|
|
|
void good_wmemcpy_s_known_dest(const wchar_t *src) {
|
|
wchar_t dst41[13];
|
|
wcscpy_s(dst41, src);
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// wmemcpy_s() - length tests
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void bad_wmemcpy_s_full_source_length(const wchar_t *src) {
|
|
wchar_t dest60[13];
|
|
wmemcpy_s(dest60, 13, src, wcslen(src));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemcpy_s' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wchar_t dest60[14];
|
|
// CHECK-FIXES-NEXT: wcscpy_s(dest60, src);
|
|
}
|
|
|
|
void good_wmemcpy_s_full_source_length(const wchar_t *src) {
|
|
wchar_t dst60[13];
|
|
wcscpy_s(dst60, src);
|
|
}
|
|
|
|
void bad_wmemcpy_s_partial_source_length(const wchar_t *src) {
|
|
wchar_t dest61[13];
|
|
wmemcpy_s(dest61, 13, src, wcslen(src) - 1);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'wmemcpy_s' is not null-terminated [bugprone-not-null-terminated-result]
|
|
// CHECK-FIXES: wchar_t dest61[14];
|
|
// CHECK-FIXES-NEXT: wcsncpy_s(dest61, src, wcslen(src) - 1);
|
|
}
|
|
|
|
void good_wmemcpy_s_partial_source_length(const wchar_t *src) {
|
|
wchar_t dst61[13];
|
|
wcsncpy_s(dst61, src, wcslen(src) - 1);
|
|
}
|