Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
71e18898
Commit
71e18898
authored
7 years ago
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix memcpy with zero size
parent
a5b56846
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
15 deletions
+16
-15
cvstd.hpp
modules/core/include/opencv2/core/cvstd.hpp
+10
-9
cvstd.inl.hpp
modules/core/include/opencv2/core/cvstd.inl.hpp
+6
-6
No files found.
modules/core/include/opencv2/core/cvstd.hpp
View file @
71e18898
...
...
@@ -598,6 +598,7 @@ String::String(const char* s)
{
if
(
!
s
)
return
;
size_t
len
=
strlen
(
s
);
if
(
!
len
)
return
;
memcpy
(
allocate
(
len
),
s
,
len
);
}
...
...
@@ -665,7 +666,7 @@ String& String::operator=(const char* s)
deallocate
();
if
(
!
s
)
return
*
this
;
size_t
len
=
strlen
(
s
);
memcpy
(
allocate
(
len
),
s
,
len
);
if
(
len
)
memcpy
(
allocate
(
len
),
s
,
len
);
return
*
this
;
}
...
...
@@ -959,8 +960,8 @@ String operator + (const String& lhs, const String& rhs)
{
String
s
;
s
.
allocate
(
lhs
.
len_
+
rhs
.
len_
);
memcpy
(
s
.
cstr_
,
lhs
.
cstr_
,
lhs
.
len_
);
memcpy
(
s
.
cstr_
+
lhs
.
len_
,
rhs
.
cstr_
,
rhs
.
len_
);
if
(
lhs
.
len_
)
memcpy
(
s
.
cstr_
,
lhs
.
cstr_
,
lhs
.
len_
);
if
(
rhs
.
len_
)
memcpy
(
s
.
cstr_
+
lhs
.
len_
,
rhs
.
cstr_
,
rhs
.
len_
);
return
s
;
}
...
...
@@ -970,8 +971,8 @@ String operator + (const String& lhs, const char* rhs)
String
s
;
size_t
rhslen
=
strlen
(
rhs
);
s
.
allocate
(
lhs
.
len_
+
rhslen
);
memcpy
(
s
.
cstr_
,
lhs
.
cstr_
,
lhs
.
len_
);
memcpy
(
s
.
cstr_
+
lhs
.
len_
,
rhs
,
rhslen
);
if
(
lhs
.
len_
)
memcpy
(
s
.
cstr_
,
lhs
.
cstr_
,
lhs
.
len_
);
if
(
rhslen
)
memcpy
(
s
.
cstr_
+
lhs
.
len_
,
rhs
,
rhslen
);
return
s
;
}
...
...
@@ -981,8 +982,8 @@ String operator + (const char* lhs, const String& rhs)
String
s
;
size_t
lhslen
=
strlen
(
lhs
);
s
.
allocate
(
lhslen
+
rhs
.
len_
);
memcpy
(
s
.
cstr_
,
lhs
,
lhslen
);
memcpy
(
s
.
cstr_
+
lhslen
,
rhs
.
cstr_
,
rhs
.
len_
);
if
(
lhslen
)
memcpy
(
s
.
cstr_
,
lhs
,
lhslen
);
if
(
rhs
.
len_
)
memcpy
(
s
.
cstr_
+
lhslen
,
rhs
.
cstr_
,
rhs
.
len_
);
return
s
;
}
...
...
@@ -991,7 +992,7 @@ String operator + (const String& lhs, char rhs)
{
String
s
;
s
.
allocate
(
lhs
.
len_
+
1
);
memcpy
(
s
.
cstr_
,
lhs
.
cstr_
,
lhs
.
len_
);
if
(
lhs
.
len_
)
memcpy
(
s
.
cstr_
,
lhs
.
cstr_
,
lhs
.
len_
);
s
.
cstr_
[
lhs
.
len_
]
=
rhs
;
return
s
;
}
...
...
@@ -1002,7 +1003,7 @@ String operator + (char lhs, const String& rhs)
String
s
;
s
.
allocate
(
rhs
.
len_
+
1
);
s
.
cstr_
[
0
]
=
lhs
;
memcpy
(
s
.
cstr_
+
1
,
rhs
.
cstr_
,
rhs
.
len_
);
if
(
rhs
.
len_
)
memcpy
(
s
.
cstr_
+
1
,
rhs
.
cstr_
,
rhs
.
len_
);
return
s
;
}
...
...
This diff is collapsed.
Click to expand it.
modules/core/include/opencv2/core/cvstd.inl.hpp
View file @
71e18898
...
...
@@ -80,7 +80,7 @@ String::String(const std::string& str)
if
(
!
str
.
empty
())
{
size_t
len
=
str
.
size
();
memcpy
(
allocate
(
len
),
str
.
c_str
(),
len
);
if
(
len
)
memcpy
(
allocate
(
len
),
str
.
c_str
(),
len
);
}
}
...
...
@@ -102,7 +102,7 @@ String& String::operator = (const std::string& str)
if
(
!
str
.
empty
())
{
size_t
len
=
str
.
size
();
memcpy
(
allocate
(
len
),
str
.
c_str
(),
len
);
if
(
len
)
memcpy
(
allocate
(
len
),
str
.
c_str
(),
len
);
}
return
*
this
;
}
...
...
@@ -126,8 +126,8 @@ String operator + (const String& lhs, const std::string& rhs)
String
s
;
size_t
rhslen
=
rhs
.
size
();
s
.
allocate
(
lhs
.
len_
+
rhslen
);
memcpy
(
s
.
cstr_
,
lhs
.
cstr_
,
lhs
.
len_
);
memcpy
(
s
.
cstr_
+
lhs
.
len_
,
rhs
.
c_str
(),
rhslen
);
if
(
lhs
.
len_
)
memcpy
(
s
.
cstr_
,
lhs
.
cstr_
,
lhs
.
len_
);
if
(
rhslen
)
memcpy
(
s
.
cstr_
+
lhs
.
len_
,
rhs
.
c_str
(),
rhslen
);
return
s
;
}
...
...
@@ -137,8 +137,8 @@ String operator + (const std::string& lhs, const String& rhs)
String
s
;
size_t
lhslen
=
lhs
.
size
();
s
.
allocate
(
lhslen
+
rhs
.
len_
);
memcpy
(
s
.
cstr_
,
lhs
.
c_str
(),
lhslen
);
memcpy
(
s
.
cstr_
+
lhslen
,
rhs
.
cstr_
,
rhs
.
len_
);
if
(
lhslen
)
memcpy
(
s
.
cstr_
,
lhs
.
c_str
(),
lhslen
);
if
(
rhs
.
len_
)
memcpy
(
s
.
cstr_
+
lhslen
,
rhs
.
cstr_
,
rhs
.
len_
);
return
s
;
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment