Skip to content

[libc] Fix implicit cast warning in strftime #127282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2025

Conversation

michaelrj-google
Copy link
Contributor

Forgot to change a size_t to an int, which caused warnings on gcc but
not clang for some reason. Regardless, this patch fixes the issue.

Forgot to change a size_t to an int, which caused warnings on gcc but
not clang for some reason. Regardless, this patch fixes the issue.
@llvmbot llvmbot added the libc label Feb 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 15, 2025

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

Forgot to change a size_t to an int, which caused warnings on gcc but
not clang for some reason. Regardless, this patch fixes the issue.


Full diff: https://github.com/llvm/llvm-project/pull/127282.diff

1 Files Affected:

  • (modified) libc/src/time/strftime_core/composite_converter.h (+2-2)
diff --git a/libc/src/time/strftime_core/composite_converter.h b/libc/src/time/strftime_core/composite_converter.h
index 5c473f172c073..3530075cfe9a9 100644
--- a/libc/src/time/strftime_core/composite_converter.h
+++ b/libc/src/time/strftime_core/composite_converter.h
@@ -171,11 +171,11 @@ LIBC_INLINE int convert_full_date_time(printf_core::Writer *writer,
   // we only pad the first conversion, and we assume all the other values are in
   // their valid ranges.
   // sizeof("Sun Jan 12 03:45:06 2025")
-  const size_t full_conv_len = 3 + 1 + 3 + 1 + 2 + 1 + 8 + 1 + 4;
+  constexpr int FULL_CONV_LEN = 3 + 1 + 3 + 1 + 2 + 1 + 8 + 1 + 4;
   // use the full conv len because this isn't being passed to a proper converter
   // that will handle the width of the leading conversion. Instead it has to be
   // handled below.
-  const int requested_padding = to_conv.min_width - full_conv_len;
+  const int requested_padding = to_conv.min_width - FULL_CONV_LEN;
 
   cpp::string_view wday_str = unwrap_opt(time_reader.get_weekday_short_name());
   cpp::string_view month_str = unwrap_opt(time_reader.get_month_short_name());

@michaelrj-google michaelrj-google merged commit 60af835 into llvm:main Feb 15, 2025
12 of 15 checks passed
@michaelrj-google
Copy link
Contributor Author

thanks for the fast review!

@michaelrj-google michaelrj-google deleted the libcStrftimeCastFix branch February 15, 2025 00:06
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
Forgot to change a size_t to an int, which caused warnings on gcc but
not clang for some reason. Regardless, this patch fixes the issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants