Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glslang
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
glslang
Commits
b329715c
Commit
b329715c
authored
Jul 11, 2015
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix clang static analyzer issues, as reported by floooh.
parent
1f654e16
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
34 deletions
+43
-34
StandAlone.cpp
StandAlone/StandAlone.cpp
+37
-23
Pp.cpp
glslang/MachineIndependent/preprocessor/Pp.cpp
+0
-2
PpContext.h
glslang/MachineIndependent/preprocessor/PpContext.h
+1
-1
PpScanner.cpp
glslang/MachineIndependent/preprocessor/PpScanner.cpp
+5
-8
No files found.
StandAlone/StandAlone.cpp
View file @
b329715c
...
...
@@ -626,6 +626,8 @@ void CompileAndLinkShaders()
char
**
shaderStrings
=
ReadFileData
(
workItem
->
name
.
c_str
());
if
(
!
shaderStrings
)
{
usage
();
delete
&
program
;
return
;
}
const
int
defaultVersion
=
Options
&
EOptionDefaultDesktop
?
110
:
100
;
...
...
@@ -945,14 +947,14 @@ int fopen_s(
//
char
**
ReadFileData
(
const
char
*
fileName
)
{
FILE
*
in
;
FILE
*
in
=
nullptr
;
int
errorCode
=
fopen_s
(
&
in
,
fileName
,
"r"
);
int
count
=
0
;
const
int
maxSourceStrings
=
5
;
char
**
return_data
=
(
char
**
)
malloc
(
sizeof
(
char
*
)
*
(
maxSourceStrings
+
1
));
const
int
maxSourceStrings
=
5
;
// for testing splitting shader/tokens across multiple strings
char
**
return_data
=
(
char
**
)
malloc
(
sizeof
(
char
*
)
*
(
maxSourceStrings
+
1
));
// freed in FreeFileData()
if
(
errorCode
)
{
if
(
errorCode
||
in
==
nullptr
)
{
printf
(
"Error: unable to open input file: %s
\n
"
,
fileName
);
return
nullptr
;
}
...
...
@@ -962,49 +964,61 @@ char** ReadFileData(const char* fileName)
fseek
(
in
,
0
,
SEEK_SET
);
char
*
fdata
=
(
char
*
)
malloc
(
count
+
2
);
char
*
fdata
=
(
char
*
)
malloc
(
count
+
2
);
// freed before return of this function
if
(
!
fdata
)
{
printf
(
"Error allocating memory
\n
"
);
return
nullptr
;
}
if
((
int
)
fread
(
fdata
,
1
,
count
,
in
)
!=
count
)
{
printf
(
"Error reading input file: %s
\n
"
,
fileName
);
return
nullptr
;
if
((
int
)
fread
(
fdata
,
1
,
count
,
in
)
!=
count
)
{
printf
(
"Error reading input file: %s
\n
"
,
fileName
);
free
(
fdata
);
return
nullptr
;
}
fdata
[
count
]
=
'\0'
;
fclose
(
in
);
if
(
count
==
0
)
{
return_data
[
0
]
=
(
char
*
)
malloc
(
count
+
2
);
// recover from empty file
return_data
[
0
]
=
(
char
*
)
malloc
(
count
+
2
);
// freed in FreeFileData()
return_data
[
0
][
0
]
=
'\0'
;
NumShaderStrings
=
0
;
return
return_data
;
free
(
fdata
);
return
return_data
;
}
else
NumShaderStrings
=
1
;
NumShaderStrings
=
1
;
// Set to larger than 1 for testing multiple strings
// compute how to split up the file into multiple strings, for testing multiple strings
int
len
=
(
int
)(
ceil
)((
float
)
count
/
(
float
)
NumShaderStrings
);
int
ptr_len
=
0
,
i
=
0
;
while
(
count
>
0
){
return_data
[
i
]
=
(
char
*
)
malloc
(
len
+
2
);
memcpy
(
return_data
[
i
],
fdata
+
ptr_len
,
len
);
return_data
[
i
][
len
]
=
'\0'
;
count
-=
(
len
);
ptr_len
+=
(
len
);
if
(
count
<
len
){
if
(
count
==
0
){
NumShaderStrings
=
(
i
+
1
);
int
ptr_len
=
0
;
int
i
=
0
;
while
(
count
>
0
)
{
return_data
[
i
]
=
(
char
*
)
malloc
(
len
+
2
);
// freed in FreeFileData()
memcpy
(
return_data
[
i
],
fdata
+
ptr_len
,
len
);
return_data
[
i
][
len
]
=
'\0'
;
count
-=
len
;
ptr_len
+=
len
;
if
(
count
<
len
)
{
if
(
count
==
0
)
{
NumShaderStrings
=
i
+
1
;
break
;
}
len
=
count
;
len
=
count
;
}
++
i
;
}
free
(
fdata
);
return
return_data
;
}
void
FreeFileData
(
char
**
data
)
{
for
(
int
i
=
0
;
i
<
NumShaderStrings
;
i
++
)
for
(
int
i
=
0
;
i
<
NumShaderStrings
;
i
++
)
free
(
data
[
i
]);
free
(
data
);
}
void
InfoLogMsg
(
const
char
*
msg
,
const
char
*
name
,
const
int
num
)
...
...
glslang/MachineIndependent/preprocessor/Pp.cpp
View file @
b329715c
...
...
@@ -817,7 +817,6 @@ int TPpContext::CPPextension(TPpToken* ppToken)
int
TPpContext
::
readCPPline
(
TPpToken
*
ppToken
)
{
int
token
=
scanToken
(
ppToken
);
bool
isVersion
=
false
;
if
(
token
==
CPP_IDENTIFIER
)
{
if
(
ppToken
->
atom
==
defineAtom
)
{
...
...
@@ -864,7 +863,6 @@ int TPpContext::readCPPline(TPpToken* ppToken)
token
=
CPPerror
(
ppToken
);
}
else
if
(
ppToken
->
atom
==
versionAtom
)
{
token
=
CPPversion
(
ppToken
);
isVersion
=
true
;
}
else
if
(
ppToken
->
atom
==
extensionAtom
)
{
token
=
CPPextension
(
ppToken
);
}
else
{
...
...
glslang/MachineIndependent/preprocessor/PpContext.h
View file @
b329715c
...
...
@@ -408,7 +408,7 @@ protected:
// handle any non-escaped newline
if
(
ch
==
'\r'
||
ch
==
'\n'
)
{
if
(
ch
==
'\r'
&&
input
->
peek
()
==
'\n'
)
ch
=
input
->
get
();
input
->
get
();
return
'\n'
;
}
...
...
glslang/MachineIndependent/preprocessor/PpScanner.cpp
View file @
b329715c
...
...
@@ -116,12 +116,11 @@ int TPpContext::InitScanner()
int
TPpContext
::
lFloatConst
(
int
len
,
int
ch
,
TPpToken
*
ppToken
)
{
bool
HasDecimalOrExponent
=
false
;
int
declen
,
exp
,
ExpSign
;
int
declen
;
int
str_len
;
int
isDouble
=
0
;
declen
=
0
;
exp
=
0
;
str_len
=
len
;
char
*
str
=
ppToken
->
name
;
...
...
@@ -152,34 +151,32 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
HasDecimalOrExponent
=
true
;
if
(
len
>=
TPpToken
::
maxTokenLength
)
{
parseContext
.
error
(
ppToken
->
loc
,
"float literal too long"
,
""
,
""
);
len
=
1
,
str_len
=
1
;
len
=
1
;
str_len
=
1
;
}
else
{
ExpSign
=
1
;
str
[
len
++
]
=
(
char
)
ch
;
ch
=
getChar
();
if
(
ch
==
'+'
)
{
str
[
len
++
]
=
(
char
)
ch
;
ch
=
getChar
();
}
else
if
(
ch
==
'-'
)
{
ExpSign
=
-
1
;
str
[
len
++
]
=
(
char
)
ch
;
ch
=
getChar
();
}
if
(
ch
>=
'0'
&&
ch
<=
'9'
)
{
while
(
ch
>=
'0'
&&
ch
<=
'9'
)
{
if
(
len
<
TPpToken
::
maxTokenLength
)
{
exp
=
exp
*
10
+
ch
-
'0'
;
str
[
len
++
]
=
(
char
)
ch
;
ch
=
getChar
();
}
else
{
parseContext
.
error
(
ppToken
->
loc
,
"float literal too long"
,
""
,
""
);
len
=
1
,
str_len
=
1
;
len
=
1
;
str_len
=
1
;
}
}
}
else
{
parseContext
.
error
(
ppToken
->
loc
,
"bad character in float exponent"
,
""
,
""
);
}
exp
*=
ExpSign
;
}
}
...
...
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