From 932ecaea3490b174451156709d84b2ebdc771d06 Mon Sep 17 00:00:00 2001 From: Scott McKay Date: Fri, 21 Feb 2020 20:07:39 +1000 Subject: [PATCH] Some documentation updates. (#3060) --- ThirdPartyNotices.txt | 26 +++++++++++++++++++ docs/Coding_Conventions_and_Standards.md | 9 ++++--- .../onnxruntime/core/framework/allocator.h | 3 +++ .../onnxruntime/core/framework/op_kernel.h | 4 +-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ThirdPartyNotices.txt b/ThirdPartyNotices.txt index 1168e26625..575224160f 100644 --- a/ThirdPartyNotices.txt +++ b/ThirdPartyNotices.txt @@ -3821,3 +3821,29 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +dcleblanc/SafeInt + +MIT License + +Copyright (c) 2018 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/docs/Coding_Conventions_and_Standards.md b/docs/Coding_Conventions_and_Standards.md index b09408c2df..a0304e1cbb 100644 --- a/docs/Coding_Conventions_and_Standards.md +++ b/docs/Coding_Conventions_and_Standards.md @@ -27,9 +27,12 @@ Other * Don't overuse std::shared\_ptr. Use std::shared\_ptr only if it's not clear when and where the object will be deallocated. See also: [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-shared_ptr](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-shared_ptr) * Avoid using the 'long' type, which could be either 32 bits or 64 bits. * If there is a legitimate need to allocate objects on the heap, prefer using onnxruntime::make_unique(). References for the reasoning: - * https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-make_unique - * https://herbsutter.com/2013/05/29/gotw-89-solution-smart-pointers/ - * https://abseil.io/tips/126 + * https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-make_unique + * https://herbsutter.com/2013/05/29/gotw-89-solution-smart-pointers/ + * https://abseil.io/tips/126 +* Use [SafeInt](https://github.com/dcleblanc/SafeInt) when calculating the size of memory to allocate to protect against overflow errors + * `#include "core/common/safeint.h"` + * search for `SafeInt` in the code for examples #### Clang-format diff --git a/include/onnxruntime/core/framework/allocator.h b/include/onnxruntime/core/framework/allocator.h index 1f4ac8812c..f3045e9964 100644 --- a/include/onnxruntime/core/framework/allocator.h +++ b/include/onnxruntime/core/framework/allocator.h @@ -153,6 +153,9 @@ using IAllocatorUniquePtr = std::unique_ptr>; class IAllocator { public: virtual ~IAllocator() = default; + /** + @remarks Use SafeInt when calculating the size of memory to allocate using Alloc. + */ virtual void* Alloc(size_t size) = 0; virtual void Free(void* p) = 0; virtual const OrtMemoryInfo& Info() const = 0; diff --git a/include/onnxruntime/core/framework/op_kernel.h b/include/onnxruntime/core/framework/op_kernel.h index dda7578706..aff045e214 100644 --- a/include/onnxruntime/core/framework/op_kernel.h +++ b/include/onnxruntime/core/framework/op_kernel.h @@ -133,8 +133,8 @@ class OpKernelContext { } /** - * return an allocator on device 0, with memtype of OrtMemTypeDefault - * + Return an allocator on device 0, with memtype of OrtMemTypeDefault. + @remarks Use SafeInt when calculating the size of memory to allocate using AllocatorPtr->Alloc. */ Status GetTempSpaceAllocator(AllocatorPtr* output) const;