Skip to content

Conversation

@vbvictor
Copy link
Contributor

@vbvictor vbvictor commented Sep 6, 2025

Part of the work in #157287.

Closes #157302.

@llvmbot
Copy link
Member

llvmbot commented Sep 6, 2025

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Baranov Victor (vbvictor)

Changes

My goal is to place all implementation of cert checks into bugprone or other modules. It's hard for the user to understand what cert-err34-c means, so we should always have human-readable alias for cert checks.

Essentially, this renaming can give "free checks" because people tend to just disable cert checks, despite most of them are regular bugprone checks that can give benefits for every project.


Patch is 25.88 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/157285.diff

13 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1)
  • (renamed) clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp (+8-6)
  • (added) clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.h (+35)
  • (modified) clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp (+4-2)
  • (modified) clang-tools-extra/clang-tidy/cert/CMakeLists.txt (-1)
  • (removed) clang-tools-extra/clang-tidy/cert/StrToNumCheck.h (-31)
  • (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4)
  • (added) clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst (+31)
  • (modified) clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst (+5-23)
  • (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+3-2)
  • (renamed) clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-string-to-number-conversion.c (+17-17)
  • (renamed) clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-string-to-number-conversion.cpp (+7-7)
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 824ebdfbd00dc..fe261e729539c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -89,6 +89,7 @@
 #include "ThrowKeywordMissingCheck.h"
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
+#include "UncheckedStringToNumberConversionCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
@@ -261,6 +262,8 @@ class BugproneModule : public ClangTidyModule {
         "bugprone-too-small-loop-variable");
     CheckFactories.registerCheck<UncheckedOptionalAccessCheck>(
         "bugprone-unchecked-optional-access");
+    CheckFactories.registerCheck<UncheckedStringToNumberConversionCheck>(
+        "bugprone-unchecked-string-to-number-conversion");
     CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>(
         "bugprone-undefined-memory-manipulation");
     CheckFactories.registerCheck<UndelegatedConstructorCheck>(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 59928e5e47a09..46bc8efd44bc5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -91,6 +91,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   ThrowKeywordMissingCheck.cpp
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
+  UncheckedStringToNumberConversionCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
similarity index 95%
rename from clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
rename to clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
index 95536bb1cfdb2..d1e7b895f9a35 100644
--- a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
@@ -1,4 +1,4 @@
-//===-- StrToNumCheck.cpp - clang-tidy ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "StrToNumCheck.h"
+#include "UncheckedStringToNumberConversionCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/FormatString.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -15,9 +15,10 @@
 
 using namespace clang::ast_matchers;
 
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
 
-void StrToNumCheck::registerMatchers(MatchFinder *Finder) {
+void UncheckedStringToNumberConversionCheck::registerMatchers(
+    MatchFinder *Finder) {
   // Match any function call to the C standard library string conversion
   // functions that do no error checking.
   Finder->addMatcher(
@@ -176,7 +177,8 @@ static StringRef classifyReplacement(ConversionKind K) {
   llvm_unreachable("Unknown conversion kind");
 }
 
-void StrToNumCheck::check(const MatchFinder::MatchResult &Result) {
+void UncheckedStringToNumberConversionCheck::check(
+    const MatchFinder::MatchResult &Result) {
   const auto *Call = Result.Nodes.getNodeAs<CallExpr>("expr");
   const FunctionDecl *FuncDecl = nullptr;
   ConversionKind Conversion = ConversionKind::None;
@@ -228,4 +230,4 @@ void StrToNumCheck::check(const MatchFinder::MatchResult &Result) {
       << classifyReplacement(Conversion);
 }
 
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.h b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.h
new file mode 100644
index 0000000000000..365b409f8311c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.h
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNCHECKEDSTRINGTONUMBERCONVERSIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNCHECKEDSTRINGTONUMBERCONVERSIONCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Guards against use of string conversion functions that do not have
+/// reasonable error handling for conversion errors.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.html
+class UncheckedStringToNumberConversionCheck : public ClangTidyCheck {
+public:
+  UncheckedStringToNumberConversionCheck(StringRef Name,
+                                         ClangTidyContext *Context)
+      : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+    return LangOpts.CPlusPlus || LangOpts.C99;
+  }
+};
+
+} // namespace clang::tidy::bugprone
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNCHECKEDSTRINGTONUMBERCONVERSIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index 66fedabaf3ca6..a0d0ac1007c3e 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -17,6 +17,7 @@
 #include "../bugprone/SizeofExpressionCheck.h"
 #include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h"
 #include "../bugprone/SuspiciousMemoryComparisonCheck.h"
+#include "../bugprone/UncheckedStringToNumberConversionCheck.h"
 #include "../bugprone/UnhandledSelfAssignmentCheck.h"
 #include "../bugprone/UnsafeFunctionsCheck.h"
 #include "../bugprone/UnusedReturnValueCheck.h"
@@ -39,7 +40,6 @@
 #include "ProperlySeededRandomGeneratorCheck.h"
 #include "SetLongJmpCheck.h"
 #include "StaticObjectExceptionCheck.h"
-#include "StrToNumCheck.h"
 #include "ThrownExceptionTypeCheck.h"
 #include "VariadicFunctionDefCheck.h"
 
@@ -297,7 +297,9 @@ class CERTModule : public ClangTidyModule {
     // ERR
     CheckFactories.registerCheck<bugprone::UnusedReturnValueCheck>(
         "cert-err33-c");
-    CheckFactories.registerCheck<StrToNumCheck>("cert-err34-c");
+    CheckFactories
+        .registerCheck<bugprone::UncheckedStringToNumberConversionCheck>(
+            "cert-err34-c");
     // EXP
     CheckFactories.registerCheck<bugprone::SuspiciousMemoryComparisonCheck>(
         "cert-exp42-c");
diff --git a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
index e3187b28399c7..eebbf907cc94e 100644
--- a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
@@ -15,7 +15,6 @@ add_clang_library(clangTidyCERTModule STATIC
   ProperlySeededRandomGeneratorCheck.cpp
   SetLongJmpCheck.cpp
   StaticObjectExceptionCheck.cpp
-  StrToNumCheck.cpp
   ThrownExceptionTypeCheck.cpp
   VariadicFunctionDefCheck.cpp
 
diff --git a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.h b/clang-tools-extra/clang-tidy/cert/StrToNumCheck.h
deleted file mode 100644
index 5306bde77f2be..0000000000000
--- a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.h
+++ /dev/null
@@ -1,31 +0,0 @@
-//===--- StrToNumCheck.h - clang-tidy----------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_STRTONUMCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_STRTONUMCHECK_H
-
-#include "../ClangTidyCheck.h"
-
-namespace clang::tidy::cert {
-
-/// Guards against use of string conversion functions that do not have
-/// reasonable error handling for conversion errors.
-///
-/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/cert/err34-c.html
-class StrToNumCheck : public ClangTidyCheck {
-public:
-  StrToNumCheck(StringRef Name, ClangTidyContext *Context)
-      : ClangTidyCheck(Name, Context) {}
-  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-};
-
-} // namespace clang::tidy::cert
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_STRTONUMCHECK_H
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 1df8b98232147..e0217cb344614 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -166,6 +166,10 @@ New checks
 New check aliases
 ^^^^^^^^^^^^^^^^^
 
+- New alias :doc:`bugprone-unchecked-string-to-number-conversion
+  <clang-tidy/checks/bugprone/unchecked-string-to-number-conversion>` to
+  :doc:`cert-err34-c <clang-tidy/checks/cert/err34-c>` was added.
+
 Changes in existing checks
 ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst
new file mode 100644
index 0000000000000..ff807e6dea5c0
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst
@@ -0,0 +1,31 @@
+.. title:: clang-tidy - bugprone-unchecked-string-to-number-conversion
+
+bugprone-unchecked-string-to-number-conversion
+=========================================
+
+This check flags calls to string-to-number conversion functions that do not
+verify the validity of the conversion, such as ``atoi()`` or ``scanf()``. It
+does not flag calls to ``strtol()``, or other, related conversion functions that
+do perform better error checking.
+
+.. code-block:: c
+
+  #include <stdlib.h>
+
+  void func(const char *buff) {
+    int si;
+
+    if (buff) {
+      si = atoi(buff); /* 'atoi' used to convert a string to an integer, but function will
+                           not report conversion errors; consider using 'strtol' instead. */
+    } else {
+      /* Handle error */
+    }
+  }
+
+References
+----------
+
+This check corresponds to the CERT C Coding Standard rule
+`ERR34-C. Detect errors when converting a string to a number
+<https://www.securecoding.cert.org/confluence/display/c/ERR34-C.+Detect+errors+when+converting+a+string+to+a+number>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst
index 362aef2098d49..dc3f6329dfb67 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst
@@ -1,28 +1,10 @@
 .. title:: clang-tidy - cert-err34-c
+.. meta::
+   :http-equiv=refresh: 5;URL=../bugprone/unchecked-string-to-number-conversion.html
 
 cert-err34-c
 ============
 
-This check flags calls to string-to-number conversion functions that do not
-verify the validity of the conversion, such as ``atoi()`` or ``scanf()``. It
-does not flag calls to ``strtol()``, or other, related conversion functions that
-do perform better error checking.
-
-.. code-block:: c
-
-  #include <stdlib.h>
-
-  void func(const char *buff) {
-    int si;
-
-    if (buff) {
-      si = atoi(buff); /* 'atoi' used to convert a string to an integer, but function will
-                           not report conversion errors; consider using 'strtol' instead. */
-    } else {
-      /* Handle error */
-    }
-  }
-
-This check corresponds to the CERT C Coding Standard rule
-`ERR34-C. Detect errors when converting a string to a number
-<https://www.securecoding.cert.org/confluence/display/c/ERR34-C.+Detect+errors+when+converting+a+string+to+a+number>`_.
+The cert-err34-c check is an alias, please see
+`bugprone-unchecked-string-to-number-conversion <../bugprone/unchecked-string-to-number-conversion.html>`_
+for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 5e3ffc4f8aca3..e6d6c3e1792f3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -157,6 +157,7 @@ Clang-Tidy Checks
    :doc:`bugprone-throw-keyword-missing <bugprone/throw-keyword-missing>`,
    :doc:`bugprone-too-small-loop-variable <bugprone/too-small-loop-variable>`,
    :doc:`bugprone-unchecked-optional-access <bugprone/unchecked-optional-access>`,
+   :doc:`bugprone-unchecked-string-to-number-conversion <bugprone/unchecked-string-to-number-conversion>`,
    :doc:`bugprone-undefined-memory-manipulation <bugprone/undefined-memory-manipulation>`,
    :doc:`bugprone-undelegated-constructor <bugprone/undelegated-constructor>`,
    :doc:`bugprone-unhandled-exception-at-new <bugprone/unhandled-exception-at-new>`,
@@ -173,7 +174,6 @@ Clang-Tidy Checks
    :doc:`cert-dcl58-cpp <cert/dcl58-cpp>`,
    :doc:`cert-env33-c <cert/env33-c>`,
    :doc:`cert-err33-c <cert/err33-c>`,
-   :doc:`cert-err34-c <cert/err34-c>`,
    :doc:`cert-err52-cpp <cert/err52-cpp>`,
    :doc:`cert-err58-cpp <cert/err58-cpp>`,
    :doc:`cert-err60-cpp <cert/err60-cpp>`,
@@ -249,12 +249,12 @@ Clang-Tidy Checks
    :doc:`linuxkernel-must-check-errs <linuxkernel/must-check-errs>`,
    :doc:`llvm-header-guard <llvm/header-guard>`,
    :doc:`llvm-include-order <llvm/include-order>`, "Yes"
-   :doc:`llvm-use-new-mlir-op-builder <llvm/use-new-mlir-op-builder>`, "Yes"
    :doc:`llvm-namespace-comment <llvm/namespace-comment>`,
    :doc:`llvm-prefer-isa-or-dyn-cast-in-conditionals <llvm/prefer-isa-or-dyn-cast-in-conditionals>`, "Yes"
    :doc:`llvm-prefer-register-over-unsigned <llvm/prefer-register-over-unsigned>`, "Yes"
    :doc:`llvm-prefer-static-over-anonymous-namespace <llvm/prefer-static-over-anonymous-namespace>`,
    :doc:`llvm-twine-local <llvm/twine-local>`, "Yes"
+   :doc:`llvm-use-new-mlir-op-builder <llvm/use-new-mlir-op-builder>`, "Yes"
    :doc:`llvmlibc-callee-namespace <llvmlibc/callee-namespace>`,
    :doc:`llvmlibc-implementation-in-namespace <llvmlibc/implementation-in-namespace>`,
    :doc:`llvmlibc-inline-function-decl <llvmlibc/inline-function-decl>`, "Yes"
@@ -436,6 +436,7 @@ Check aliases
    :doc:`cert-dcl54-cpp <cert/dcl54-cpp>`, :doc:`misc-new-delete-overloads <misc/new-delete-overloads>`,
    :doc:`cert-dcl59-cpp <cert/dcl59-cpp>`, :doc:`google-build-namespaces <google/build-namespaces>`,
    :doc:`cert-err09-cpp <cert/err09-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
+   :doc:`cert-err34-c <cert/err34-c>`, :doc:`bugprone-unchecked-string-to-number-conversion <bugprone/unchecked-string-to-number-conversion>`,
    :doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
    :doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
    :doc:`cert-fio38-c <cert/fio38-c>`, :doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/err34-c.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-string-to-number-conversion.c
similarity index 77%
rename from clang-tools-extra/test/clang-tidy/checkers/cert/err34-c.c
rename to clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-string-to-number-conversion.c
index e2cfc2182b3ef..0546e0c2091d5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/err34-c.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-string-to-number-conversion.c
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cert-err34-c %t -- -- -std=c11
+// RUN: %check_clang_tidy %s bugprone-unchecked-string-to-number-conversion %t
 
 typedef __SIZE_TYPE__      size_t;
 typedef signed             ptrdiff_t;
@@ -8,9 +8,9 @@ typedef void *             FILE;
 
 extern FILE *stdin;
 
-extern int fscanf(FILE * restrict stream, const char * restrict format, ...);
-extern int scanf(const char * restrict format, ...);
-extern int sscanf(const char * restrict s, const char * restrict format, ...);
+extern int fscanf(FILE *stream, const char *format, ...);
+extern int scanf(const char *format, ...);
+extern int sscanf(const char *s, const char *format, ...);
 
 extern double atof(const char *nptr);
 extern int atoi(const char *nptr);
@@ -28,23 +28,23 @@ void f1(const char *in) {
   double d;
   long double ld;
 
-  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'sscanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtol' instead [cert-err34-c]
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'sscanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtol' instead [bugprone-unchecked-string-to-number-conversion]
   sscanf(in, "%d", &i);
-  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'fscanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtoll' instead [cert-err34-c]
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'fscanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtoll' instead
   fscanf(stdin, "%lld", &ll);
-  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'sscanf' used to convert a string to an unsigned integer value, but function will not report conversion errors; consider using 'strtoul' instead [cert-err34-c]
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'sscanf' used to convert a string to an unsigned integer value, but function will not report conversion errors; consider using 'strtoul' instead
   sscanf(in, "%u", &ui);
-  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'fscanf' used to convert a string to an unsigned integer value, but function will not report conversion errors; consider using 'strtoull' instead [cert-err34-c]
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'fscanf' used to convert a string to an unsigned integer value, but function will not report conversion errors; consider using 'strtoull' instead
   fscanf(stdin, "%llu", &ull);
-  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'scanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtoimax' instead [cert-err34-c]
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'scanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtoimax' instead
   scanf("%jd", &im);
-  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'fscanf' used to convert a string to an unsigned integer value, but function will not report conversion errors; consider using 'strtoumax' instead [cert-err34-c]
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'fscanf' used to convert a string to an unsigned integer value, but function will not report conversion errors; consider using 'strtoumax' instead
   fscanf(stdin, "%ju", &uim);
-  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'sscanf' used to convert a string to a floating-point value, but function will not report conversion errors; consider using 'strtof' instead [cert-err34-c]
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'sscanf' used to convert a string to a floating-point value, but function will not report conversion errors; consider using 'strtof' instead
   sscanf(in, "%f", &f); // to float
-  // CHECK-MESSAGES: :[[@LIN...
[truncated]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is mostly copypaste from StrToNumCheck.h

Copy link
Contributor Author

@vbvictor vbvictor Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is copy-paste from previous err34-c.rst

@carlosgalvezp
Copy link
Contributor

Great initiative, thank you! I will review soon.

The commit message title can be a bit misleading, I read it as "create a new alias in bugprone, which points to the cert check", but in reality the intention is the other way around, alias from bugprone to cert.

@vbvictor vbvictor changed the title [clang-tidy] Add new alias 'bugprone-unchecked-string-to-number-conversion' for 'cert-err34-c' [clang-tidy] Rename 'cert-err34-c' to 'bugprone-unchecked-string-to-number-conversion' Sep 6, 2025
@vbvictor vbvictor force-pushed the new-alias-for-cert-err34-c branch from 5218da9 to 47df1d5 Compare September 6, 2025 18:11
@vbvictor
Copy link
Contributor Author

vbvictor commented Sep 6, 2025

The commit message title can be a bit misleading, I read it as "create a new alias in bugprone, which points to the cert check", but in reality the intention is the other way around, alias from bugprone to cert.

Yeah, it was tricky to write. I hope "rename" would be more clear

@vbvictor
Copy link
Contributor Author

vbvictor commented Sep 6, 2025

FYI, I created a tracking-progress issue #157287. Help is welcome :)
I wonder if this could be considered a "good first issue"..?

Copy link
Contributor

@carlosgalvezp carlosgalvezp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@vbvictor vbvictor merged commit 65f9c08 into llvm:main Sep 9, 2025
10 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 9, 2025

LLVM Buildbot has detected a new failure on builder clang-armv8-quick running on linaro-clang-armv8-quick while building clang-tools-extra at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/154/builds/21282

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'lit :: timeout-hang.py' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 18
not env -u FILECHECK_OPTS "/usr/bin/python3.10" /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt  --timeout=15 --param external=0 | "/usr/bin/python3.10" /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/utils/lit/tests/timeout-hang.py 5
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3.10 /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt --timeout=15 --param external=0
# .---command stderr------------
# | lit.py: /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/llvm/utils/lit/lit/main.py:74: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 15 seconds was requested on the command line. Forcing timeout to be 15 seconds.
# `-----------------------------
# executed command: /usr/bin/python3.10 /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/utils/lit/tests/timeout-hang.py 5
# .---command stdout------------
# | Testing took 6.68s, which is beyond the grace period of 5.0s
# `-----------------------------
# error: command failed with exit status: 1

--

********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[clang-tidy] Move 'cert-err34-c' check outside of 'cert' module and give a proper name

5 participants