strcpy() returns a pointer to the destination string, AsciiStrCpyS()
does not. So a simple #define does not work. Create a inline function
instead.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
CryptoPkg/Library/Include/CrtLibSupport.h | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/CryptoPkg/Library/Include/CrtLibSupport.h b/CryptoPkg/Library/Include/CrtLibSupport.h
index 287d7f76bfb3..7c1bc7755b1c 100644
--- a/CryptoPkg/Library/Include/CrtLibSupport.h
+++ b/CryptoPkg/Library/Include/CrtLibSupport.h
@@ -395,6 +395,16 @@ inet_pton (
void *
);
+static inline char *
+strcpy (
+ char *restrict strDest,
+ const char *strSource
+ )
+{
+ AsciiStrCpyS (strDest, MAX_STRING_SIZE, strSource);
+ return strDest;
+}
+
//
// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
//
@@ -404,7 +414,6 @@ inet_pton (
#define memcmp(buf1, buf2, count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
#define memmove(dest, source, count) CopyMem(dest,source,(UINTN)(count))
#define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
-#define strcpy(strDest, strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)
#define strncpy(strDest, strSource, count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
#define strcat(strDest, strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)
#define strncmp(string1, string2, count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
--
2.35.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#88629): https://edk2.groups.io/g/devel/message/88629
Mute This Topic: https://groups.io/mt/90333060/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Can we remove inline keyword?
I don't think it is really needed in EDKII project.
Thank you
Yao Jiewen
> -----Original Message-----
> From: Gerd Hoffmann <kraxel@redhat.com>
> Sent: Friday, April 8, 2022 7:16 PM
> To: devel@edk2.groups.io
> Cc: Oliver Steffen <osteffen@redhat.com>; Yao, Jiewen
> <jiewen.yao@intel.com>; Jiang, Guomin <guomin.jiang@intel.com>; Wang, Jian
> J <jian.j.wang@intel.com>; Xiaoyu Lu <xiaoyux.lu@intel.com>; Pawel Polawski
> <ppolawsk@redhat.com>; Gerd Hoffmann <kraxel@redhat.com>
> Subject: [PATCH v2 7/8] CryptoPkg/CrtLibSupport: fix strcpy
>
> strcpy() returns a pointer to the destination string, AsciiStrCpyS()
> does not. So a simple #define does not work. Create a inline function
> instead.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> CryptoPkg/Library/Include/CrtLibSupport.h | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/CryptoPkg/Library/Include/CrtLibSupport.h
> b/CryptoPkg/Library/Include/CrtLibSupport.h
> index 287d7f76bfb3..7c1bc7755b1c 100644
> --- a/CryptoPkg/Library/Include/CrtLibSupport.h
> +++ b/CryptoPkg/Library/Include/CrtLibSupport.h
> @@ -395,6 +395,16 @@ inet_pton (
> void *
> );
>
> +static inline char *
> +strcpy (
> + char *restrict strDest,
> + const char *strSource
> + )
> +{
> + AsciiStrCpyS (strDest, MAX_STRING_SIZE, strSource);
> + return strDest;
> +}
> +
> //
> // Macros that directly map functions to BaseLib, BaseMemoryLib, and
> DebugLib functions
> //
> @@ -404,7 +414,6 @@ inet_pton (
> #define memcmp(buf1, buf2, count)
> (int)(CompareMem(buf1,buf2,(UINTN)(count)))
> #define memmove(dest, source, count)
> CopyMem(dest,source,(UINTN)(count))
> #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
> -#define strcpy(strDest, strSource)
> AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)
> #define strncpy(strDest, strSource, count)
> AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
> #define strcat(strDest, strSource)
> AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)
> #define strncmp(string1, string2, count)
> (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
> --
> 2.35.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#88636): https://edk2.groups.io/g/devel/message/88636
Mute This Topic: https://groups.io/mt/90333060/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On Fri, Apr 08, 2022 at 12:18:17PM +0000, Yao, Jiewen wrote: > Can we remove inline keyword? > > I don't think it is really needed in EDKII project. Well, in the header file it is, otherwise we'll get duplicate symbol errors. We could probably move the implementation from CryptoPkg/Library/Include/CrtLibSupport.h to CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c, then drop the inline keyword. take care, Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#88683): https://edk2.groups.io/g/devel/message/88683 Mute This Topic: https://groups.io/mt/90333060/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
OK. Having implementation in .h is not allowed in EDKII. Sorry, I missed that. Please move it to CrtWrapper.c and drop inline. > -----Original Message----- > From: Gerd Hoffmann <kraxel@redhat.com> > Sent: Monday, April 11, 2022 2:59 PM > To: Yao, Jiewen <jiewen.yao@intel.com> > Cc: devel@edk2.groups.io; Oliver Steffen <osteffen@redhat.com>; Jiang, > Guomin <guomin.jiang@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; > Xiaoyu Lu <xiaoyux.lu@intel.com>; Pawel Polawski <ppolawsk@redhat.com> > Subject: Re: [PATCH v2 7/8] CryptoPkg/CrtLibSupport: fix strcpy > > On Fri, Apr 08, 2022 at 12:18:17PM +0000, Yao, Jiewen wrote: > > Can we remove inline keyword? > > > > I don't think it is really needed in EDKII project. > > Well, in the header file it is, otherwise we'll get duplicate symbol > errors. > > We could probably move the implementation from > CryptoPkg/Library/Include/CrtLibSupport.h to > CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c, > then drop the inline keyword. > > take care, > Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#88688): https://edk2.groups.io/g/devel/message/88688 Mute This Topic: https://groups.io/mt/90333060/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.