Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
1acc6dcc
Commit
1acc6dcc
authored
Sep 29, 2016
by
Huw Davies
Committed by
Alexandre Julliard
Sep 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
riched20: Add checks for allocation failures.
Signed-off-by:
Huw Davies
<
huw@codeweavers.com
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
b3b5c256
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
11 deletions
+24
-11
string.c
dlls/riched20/string.c
+24
-11
No files found.
dlls/riched20/string.c
View file @
1acc6dcc
...
...
@@ -24,19 +24,23 @@ WINE_DEFAULT_DEBUG_CHANNEL(richedit);
static
int
ME_GetOptimalBuffer
(
int
nLen
)
{
/* FIXME: This seems wasteful for tabs and end of lines strings,
* since they have a small fixed length. */
return
((
sizeof
(
WCHAR
)
*
nLen
)
+
128
)
&
~
63
;
}
/* Create a buffer (uninitialized string) of size nMaxChars */
static
ME_String
*
ME_MakeStringB
(
int
nMaxChars
)
{
ME_String
*
s
=
ALLOC_OBJ
(
ME_String
);
ME_String
*
s
=
heap_alloc
(
sizeof
(
*
s
)
);
if
(
!
s
)
return
NULL
;
s
->
nLen
=
nMaxChars
;
s
->
nBuffer
=
ME_GetOptimalBuffer
(
s
->
nLen
+
1
);
s
->
szData
=
ALLOC_N_OBJ
(
WCHAR
,
s
->
nBuffer
);
s
->
szData
=
heap_alloc
(
s
->
nBuffer
*
sizeof
(
WCHAR
)
);
if
(
!
s
->
szData
)
{
heap_free
(
s
);
return
NULL
;
}
s
->
szData
[
s
->
nLen
]
=
0
;
return
s
;
}
...
...
@@ -44,7 +48,8 @@ static ME_String *ME_MakeStringB(int nMaxChars)
ME_String
*
ME_MakeStringN
(
LPCWSTR
szText
,
int
nMaxChars
)
{
ME_String
*
s
=
ME_MakeStringB
(
nMaxChars
);
/* Native allows NULL chars */
if
(
!
s
)
return
NULL
;
memcpy
(
s
->
szData
,
szText
,
s
->
nLen
*
sizeof
(
WCHAR
));
return
s
;
}
...
...
@@ -54,6 +59,8 @@ ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars)
{
int
i
;
ME_String
*
s
=
ME_MakeStringB
(
nMaxChars
);
if
(
!
s
)
return
NULL
;
for
(
i
=
0
;
i
<
nMaxChars
;
i
++
)
s
->
szData
[
i
]
=
cRepeat
;
return
s
;
...
...
@@ -62,20 +69,23 @@ ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars)
void
ME_DestroyString
(
ME_String
*
s
)
{
if
(
!
s
)
return
;
FREE_OBJ
(
s
->
szData
);
FREE_OBJ
(
s
);
heap_free
(
s
->
szData
);
heap_free
(
s
);
}
BOOL
ME_InsertString
(
ME_String
*
s
,
int
ofs
,
const
WCHAR
*
insert
,
int
len
)
{
DWORD
new_len
=
s
->
nLen
+
len
+
1
;
WCHAR
*
new
;
assert
(
ofs
<=
s
->
nLen
);
if
(
new_len
>
s
->
nBuffer
)
{
s
->
nBuffer
=
ME_GetOptimalBuffer
(
new_len
);
s
->
szData
=
heap_realloc
(
s
->
szData
,
s
->
nBuffer
*
sizeof
(
WCHAR
)
);
if
(
!
s
->
szData
)
return
FALSE
;
new
=
heap_realloc
(
s
->
szData
,
s
->
nBuffer
*
sizeof
(
WCHAR
)
);
if
(
!
new
)
return
FALSE
;
s
->
szData
=
new
;
}
memmove
(
s
->
szData
+
ofs
+
len
,
s
->
szData
+
ofs
,
(
s
->
nLen
-
ofs
+
1
)
*
sizeof
(
WCHAR
)
);
...
...
@@ -101,6 +111,8 @@ ME_String *ME_VSplitString(ME_String *orig, int charidx)
assert
(
charidx
<=
orig
->
nLen
);
s
=
ME_MakeStringN
(
orig
->
szData
+
charidx
,
orig
->
nLen
-
charidx
);
if
(
!
s
)
return
NULL
;
orig
->
nLen
=
charidx
;
orig
->
szData
[
charidx
]
=
'\0'
;
return
s
;
...
...
@@ -163,6 +175,7 @@ ME_CallWordBreakProc(ME_TextEditor *editor, WCHAR *str, INT len, INT start, INT
int
buffer_size
=
WideCharToMultiByte
(
CP_ACP
,
0
,
str
,
len
,
NULL
,
0
,
NULL
,
NULL
);
char
*
buffer
=
heap_alloc
(
buffer_size
);
if
(
!
buffer
)
return
0
;
WideCharToMultiByte
(
CP_ACP
,
0
,
str
,
len
,
buffer
,
buffer_size
,
NULL
,
NULL
);
result
=
editor
->
pfnWordBreak
((
WCHAR
*
)
buffer
,
start
,
buffer_size
,
code
);
...
...
@@ -187,7 +200,7 @@ LPWSTR ME_ToUnicode(LONG codepage, LPVOID psz, INT *len)
if
(
!
nChars
)
return
NULL
;
if
((
tmp
=
ALLOC_N_OBJ
(
WCHAR
,
nChars
))
!=
NULL
)
if
((
tmp
=
heap_alloc
(
nChars
*
sizeof
(
WCHAR
)
))
!=
NULL
)
*
len
=
MultiByteToWideChar
(
codepage
,
0
,
psz
,
-
1
,
tmp
,
nChars
)
-
1
;
return
tmp
;
}
...
...
@@ -196,5 +209,5 @@ LPWSTR ME_ToUnicode(LONG codepage, LPVOID psz, INT *len)
void
ME_EndToUnicode
(
LONG
codepage
,
LPVOID
psz
)
{
if
(
codepage
!=
CP_UNICODE
)
FREE_OBJ
(
psz
);
heap_free
(
psz
);
}
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