From 40003c405451d90f5eb1d74f2ba036a1036bbc2a Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Sun, 1 Oct 2023 22:44:38 +0200 Subject: [PATCH] COM: Improve bstr constructors Signed-off-by: Simon Rozman --- include/WinStd/COM.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/WinStd/COM.h b/include/WinStd/COM.h index 97901aa8..d32fb45f 100644 --- a/include/WinStd/COM.h +++ b/include/WinStd/COM.h @@ -1,4 +1,4 @@ -/* +/* SPDX-License-Identifier: MIT Copyright © 1991-2023 Amebis Copyright © 2016 GÉANT @@ -202,7 +202,7 @@ namespace winstd /// /// Constructs BSTR from OLE string /// - bstr(_In_ LPCOLESTR src) + bstr(_In_opt_z_ LPCOLESTR src) { m_h = SysAllocString(src); if (!m_h) @@ -212,7 +212,7 @@ namespace winstd /// /// Constructs BSTR from OLE string with length /// - bstr(_In_ LPCOLESTR src, _In_ UINT len) + bstr(_In_reads_opt_(len) LPCOLESTR src, _In_ UINT len) { m_h = SysAllocStringLen(src, len); if (!m_h) @@ -223,8 +223,10 @@ namespace winstd /// Constructs BSTR from std::basic_string /// template - bstr(_In_ const std::basic_string &src) + bstr(_In_ const std::basic_string &src) { + if (src.length() >= UINT_MAX) + throw std::invalid_argument("String too long"); m_h = SysAllocStringLen(src.c_str(), (UINT)src.length()); if (!m_h) throw std::bad_alloc();