-
Notifications
You must be signed in to change notification settings - Fork 537
Replace deprecated APIs in core/common #9825
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
Draft
hyunjiki-amd
wants to merge
9
commits into
Xilinx:master
Choose a base branch
from
hyunjiki-amd:banned-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+10
−9
Draft
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
44e0e18
Replace banned APIs
hyunjiki-amd 7b85909
Add secure cross-platform wrapper
hyunjiki-amd 0aba05d
Modify str_wrapper.h to exclude Linux implementation
hyunjiki-amd 42e6b17
Modify str_wrapper.h and add str_wrapper.cpp
hyunjiki-amd e4c9b1b
Add an example usage of xrt_core::str_wrapper
hyunjiki-amd c775736
Add str_wrapper.cpp to the build
hyunjiki-amd 8b49f3b
Modify xrt_error.cpp and add rt_printf_impl.cpp as an example
hyunjiki-amd 610fa6e
Remove the wrapper
hyunjiki-amd f25f0d6
Change xrt_xclbin.cpp
hyunjiki-amd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /** | ||
| * Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| * not use this file except in compliance with the License. A copy of the | ||
| * License is located at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| // Cross-platform wrapper for banned C string APIs | ||
| // Provides secure replacements for Windows driver compliance | ||
|
|
||
| #ifndef SAFE_STR_WRAPPER_H_ | ||
| #define SAFE_STR_WRAPPER_H_ | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
|
|
||
| #include <errno.h> | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
| #include <stddef.h> | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
| #include <stdio.h> | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
| #include <string.h> | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
| #include <cstring> | ||
| #include <stdarg.h> | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
|
|
||
| #ifdef _WIN32 | ||
|
|
||
| #undef strcpy // No bounds checking | ||
| #define strcpy(dest, src) strcpy_s((dest), sizeof(dest), (src)) | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
|
|
||
| #undef strncpy // Limited error detection | ||
| #define strncpy(dest, src, n) strncpy_s((dest), sizeof(dest), (src), (n)) | ||
|
|
||
| #undef strcat // Limited error detection | ||
| #define strcat(dest, src) strcat_s((dest), sizeof(dest), (src)) | ||
|
|
||
| #undef strncat // Limited error detection | ||
| #define strncat(dest, src, n) strncat_s((dest), sizeof(dest), (src), (n)) | ||
|
|
||
| #undef sprintf // Limited error detection | ||
| #define sprintf(buf, format, ...) sprintf_s((buf), sizeof(buf), (format), ##__VA_ARGS__) | ||
|
|
||
| #undef vsnprintf // Limited error detection | ||
| #define vsnprintf(buf, size, format, args) vsnprintf_s((buf), sizeof(buf), (size), (format), (args)) | ||
|
|
||
| #else | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
| namespace xrt_str_safe { | ||
|
|
||
| inline errno_t strcpy_safe(char* dest, size_t dest_size, const char* src) { | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
| if (!dest || !src || dest_size == 0) return EINVAL; | ||
| size_t src_len = strlen(src); | ||
| if (src_len >= dest_size) return ERANGE; | ||
| std::strcpy(dest, src); | ||
| return 0; | ||
| } | ||
|
|
||
| inline errno_t strncpy_safe(char* dest, size_t dest_size, const char* src, size_t count) { | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
| if (!dest || !src || dest_size == 0) return EINVAL; | ||
| size_t copy_len = (count < dest_size - 1) ? count : dest_size - 1; | ||
| std::strncpy(dest, src, copy_len); | ||
| dest[copy_len] = '\0'; | ||
| return 0; | ||
| } | ||
|
|
||
| inline errno_t strcat_safe(char* dest, size_t dest_size, const char* src) { | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
| if (!dest || !src || dest_size == 0) return EINVAL; | ||
| size_t dest_len = strlen(dest); | ||
| size_t src_len = strlen(src); | ||
| if (dest_len + src_len >= dest_size) return ERANGE; | ||
| std::strcat(dest, src); | ||
| return 0; | ||
| } | ||
|
|
||
| inline errno_t strncat_safe(char* dest, size_t dest_size, const char* src, size_t count) { | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
| if (!dest || !src || dest_size == 0) return EINVAL; | ||
| size_t dest_len = strlen(dest); | ||
| size_t available = dest_size - dest_len - 1; | ||
| size_t copy_len = (count < available) ? count : available; | ||
| std::strncat(dest, src, copy_len); | ||
| return 0; | ||
| } | ||
|
|
||
| } // namespace xrt_str_safe | ||
|
|
||
| #undef strcpy | ||
| #define strcpy(dest, src) (xrt_str_safe::strcpy_safe((dest), sizeof(dest), (src)), (dest)) | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
|
|
||
| #undef strncpy | ||
| #define strncpy(dest, src, n) (xrt_str_safe::strncpy_safe((dest), sizeof(dest), (src), (n)), (dest)) | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
|
|
||
| #undef strcat | ||
| #define strcat(dest, src) (xrt_str_safe::strcat_safe((dest), sizeof(dest), (src)), (dest)) | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
|
|
||
| #undef strncat | ||
| #define strncat(dest, src, n) (xrt_str_safe::strncat_safe((dest), sizeof(dest), (src), (n)), (dest)) | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
|
|
||
| #undef sprintf | ||
| #define sprintf(buf, format, ...) std::snprintf((buf), sizeof(buf), (format), ##__VA_ARGS__) | ||
|
hyunjiki-amd marked this conversation as resolved.
Outdated
|
||
|
|
||
| #endif // _WIN32 | ||
|
|
||
| #endif // SAFE_STR_WRAPPER_H_ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.