Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
013c5cb0
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
013c5cb0
编写于
3月 14, 2021
作者:
sangshuduo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-3197] <fix>: fix coverity scan issues. use secure random()
上级
3983f14e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
23 deletion
+36
-23
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+36
-23
未找到文件。
src/kit/taosdemo/taosdemo.c
浏览文件 @
013c5cb0
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
#define CURL_STATICLIB
#define CURL_STATICLIB
#ifdef LINUX
#ifdef LINUX
#include "os.h"
#include <argp.h>
#include <argp.h>
#include <assert.h>
#include <assert.h>
#include <inttypes.h>
#include <inttypes.h>
...
@@ -33,7 +32,6 @@
...
@@ -33,7 +32,6 @@
#include <semaphore.h>
#include <semaphore.h>
#include <stdbool.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/time.h>
#include <sys/time.h>
#include <time.h>
#include <time.h>
...
@@ -44,18 +42,12 @@
...
@@ -44,18 +42,12 @@
#include <assert.h>
#include <assert.h>
#include <regex.h>
#include <regex.h>
#include <stdio.h>
#include <stdio.h>
#include "os.h"
#ifdef WINDOWS
#include <winsock2.h>
typedef
unsigned
__int32
uint32_t
;
#pragma comment ( lib, "ws2_32.lib" )
#endif
#endif
#endif
#include <stdlib.h>
#include "cJSON.h"
#include "cJSON.h"
#include "os.h"
#include "taos.h"
#include "taos.h"
#include "taoserror.h"
#include "taoserror.h"
#include "tutil.h"
#include "tutil.h"
...
@@ -418,11 +410,18 @@ typedef struct SThreadInfo_S {
...
@@ -418,11 +410,18 @@ typedef struct SThreadInfo_S {
}
threadInfo
;
}
threadInfo
;
#ifdef WINDOWS
#ifdef WINDOWS
#define _CRT_RAND_S
#include <windows.h>
#include <windows.h>
#include <winsock2.h>
typedef
unsigned
__int32
uint32_t
;
#pragma comment ( lib, "ws2_32.lib" )
// Some old MinGW/CYGWIN distributions don't define this:
// Some old MinGW/CYGWIN distributions don't define this:
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif
#endif
// ENABLE_VIRTUAL_TERMINAL_PROCESSING
static
HANDLE
g_stdoutHandle
;
static
HANDLE
g_stdoutHandle
;
static
DWORD
g_consoleMode
;
static
DWORD
g_consoleMode
;
...
@@ -458,6 +457,14 @@ void resetAfterAnsiEscape(void) {
...
@@ -458,6 +457,14 @@ void resetAfterAnsiEscape(void) {
exit
(
GetLastError
());
exit
(
GetLastError
());
}
}
}
}
int
taosRandom
()
{
int
number
;
rand_s
(
&
number
);
return
number
;
}
#else
#else
void
setupForAnsiEscape
(
void
)
{}
void
setupForAnsiEscape
(
void
)
{}
...
@@ -465,6 +472,12 @@ void resetAfterAnsiEscape(void) {
...
@@ -465,6 +472,12 @@ void resetAfterAnsiEscape(void) {
// Reset colors
// Reset colors
printf
(
"
\x1b
[0m"
);
printf
(
"
\x1b
[0m"
);
}
}
int
taosRandom
()
{
return
random
();
}
#endif
#endif
static
int
createDatabases
();
static
int
createDatabases
();
...
@@ -977,10 +990,10 @@ static double rand_double() {
...
@@ -977,10 +990,10 @@ static double rand_double() {
static
void
init_rand_data
()
{
static
void
init_rand_data
()
{
for
(
int
i
=
0
;
i
<
MAX_PREPARED_RAND
;
i
++
){
for
(
int
i
=
0
;
i
<
MAX_PREPARED_RAND
;
i
++
){
randint
[
i
]
=
(
int
)(
rand
()
%
65535
);
randint
[
i
]
=
(
int
)(
taosRandom
()
%
65535
);
randbigint
[
i
]
=
(
int64_t
)(
rand
()
%
2147483648
);
randbigint
[
i
]
=
(
int64_t
)(
taosRandom
()
%
2147483648
);
randfloat
[
i
]
=
(
float
)(
rand
()
/
1000
.
0
);
randfloat
[
i
]
=
(
float
)(
taosRandom
()
/
1000
.
0
);
randdouble
[
i
]
=
(
double
)(
rand
()
/
1000000
.
0
);
randdouble
[
i
]
=
(
double
)(
taosRandom
()
/
1000000
.
0
);
}
}
}
}
...
@@ -4119,7 +4132,7 @@ static void syncWriteForNumberOfTblInOneSql(
...
@@ -4119,7 +4132,7 @@ static void syncWriteForNumberOfTblInOneSql(
int
rand_num
=
rand_tinyint
()
%
100
;
int
rand_num
=
rand_tinyint
()
%
100
;
if
(
0
!=
superTblInfo
->
disorderRatio
if
(
0
!=
superTblInfo
->
disorderRatio
&&
rand_num
<
superTblInfo
->
disorderRatio
)
{
&&
rand_num
<
superTblInfo
->
disorderRatio
)
{
int64_t
d
=
start_time
-
rand
()
%
superTblInfo
->
disorderRange
;
int64_t
d
=
start_time
-
taosRandom
()
%
superTblInfo
->
disorderRange
;
retLen
=
generateRowData
(
pstr
+
len
,
retLen
=
generateRowData
(
pstr
+
len
,
superTblInfo
->
maxSqlLen
-
len
,
superTblInfo
->
maxSqlLen
-
len
,
d
,
d
,
...
@@ -4270,7 +4283,7 @@ int32_t generateData(char *res, char **data_type,
...
@@ -4270,7 +4283,7 @@ int32_t generateData(char *res, char **data_type,
double
t
=
rand_double
();
double
t
=
rand_double
();
pstr
+=
sprintf
(
pstr
,
", %20.8f"
,
t
);
pstr
+=
sprintf
(
pstr
,
", %20.8f"
,
t
);
}
else
if
(
strcasecmp
(
data_type
[
i
%
c
],
"bool"
)
==
0
)
{
}
else
if
(
strcasecmp
(
data_type
[
i
%
c
],
"bool"
)
==
0
)
{
bool
b
=
rand
()
&
1
;
bool
b
=
taosRandom
()
&
1
;
pstr
+=
sprintf
(
pstr
,
", %s"
,
b
?
"true"
:
"false"
);
pstr
+=
sprintf
(
pstr
,
", %s"
,
b
?
"true"
:
"false"
);
}
else
if
(
strcasecmp
(
data_type
[
i
%
c
],
"binary"
)
==
0
)
{
}
else
if
(
strcasecmp
(
data_type
[
i
%
c
],
"binary"
)
==
0
)
{
char
*
s
=
malloc
(
lenOfBinary
);
char
*
s
=
malloc
(
lenOfBinary
);
...
@@ -4464,7 +4477,7 @@ static int generateDataBuffer(int32_t tableSeq,
...
@@ -4464,7 +4477,7 @@ static int generateDataBuffer(int32_t tableSeq,
int
rand_num
=
rand_tinyint
()
%
100
;
int
rand_num
=
rand_tinyint
()
%
100
;
if
(
0
!=
superTblInfo
->
disorderRatio
if
(
0
!=
superTblInfo
->
disorderRatio
&&
rand_num
<
superTblInfo
->
disorderRatio
)
{
&&
rand_num
<
superTblInfo
->
disorderRatio
)
{
int64_t
d
=
startTime
-
rand
()
%
superTblInfo
->
disorderRange
;
int64_t
d
=
startTime
-
taosRandom
()
%
superTblInfo
->
disorderRange
;
retLen
=
generateRowData
(
retLen
=
generateRowData
(
pstr
+
len
,
pstr
+
len
,
superTblInfo
->
maxSqlLen
-
len
,
superTblInfo
->
maxSqlLen
-
len
,
...
@@ -4487,7 +4500,7 @@ static int generateDataBuffer(int32_t tableSeq,
...
@@ -4487,7 +4500,7 @@ static int generateDataBuffer(int32_t tableSeq,
len
+=
retLen
;
len
+=
retLen
;
}
}
}
else
{
}
else
{
int
rand_num
=
rand
()
%
100
;
int
rand_num
=
taosRandom
()
%
100
;
char
data
[
MAX_DATA_SIZE
];
char
data
[
MAX_DATA_SIZE
];
char
**
data_type
=
g_args
.
datatype
;
char
**
data_type
=
g_args
.
datatype
;
int
lenOfBinary
=
g_args
.
len_of_binary
;
int
lenOfBinary
=
g_args
.
len_of_binary
;
...
@@ -4495,7 +4508,7 @@ static int generateDataBuffer(int32_t tableSeq,
...
@@ -4495,7 +4508,7 @@ static int generateDataBuffer(int32_t tableSeq,
if
((
g_args
.
disorderRatio
!=
0
)
if
((
g_args
.
disorderRatio
!=
0
)
&&
(
rand_num
<
g_args
.
disorderRange
))
{
&&
(
rand_num
<
g_args
.
disorderRange
))
{
int64_t
d
=
startTime
-
rand
()
%
1000000
+
rand_num
;
int64_t
d
=
startTime
-
taosRandom
()
%
1000000
+
rand_num
;
len
=
generateData
(
data
,
data_type
,
len
=
generateData
(
data
,
data_type
,
ncols_per_record
,
d
,
lenOfBinary
);
ncols_per_record
,
d
,
lenOfBinary
);
}
else
{
}
else
{
...
@@ -4682,10 +4695,10 @@ void callBack(void *param, TAOS_RES *res, int code) {
...
@@ -4682,10 +4695,10 @@ void callBack(void *param, TAOS_RES *res, int code) {
}
}
for
(
int
i
=
0
;
i
<
g_args
.
num_of_RPR
;
i
++
)
{
for
(
int
i
=
0
;
i
<
g_args
.
num_of_RPR
;
i
++
)
{
int
rand_num
=
rand
()
%
100
;
int
rand_num
=
taosRandom
()
%
100
;
if
(
0
!=
winfo
->
superTblInfo
->
disorderRatio
&&
rand_num
<
winfo
->
superTblInfo
->
disorderRatio
)
if
(
0
!=
winfo
->
superTblInfo
->
disorderRatio
&&
rand_num
<
winfo
->
superTblInfo
->
disorderRatio
)
{
{
int64_t
d
=
winfo
->
lastTs
-
rand
()
%
1000000
+
rand_num
;
int64_t
d
=
winfo
->
lastTs
-
taosRandom
()
%
1000000
+
rand_num
;
//generateData(data, datatype, ncols_per_record, d, len_of_binary);
//generateData(data, datatype, ncols_per_record, d, len_of_binary);
(
void
)
generateRowData
(
data
,
MAX_DATA_SIZE
,
d
,
winfo
->
superTblInfo
);
(
void
)
generateRowData
(
data
,
MAX_DATA_SIZE
,
d
,
winfo
->
superTblInfo
);
}
else
{
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录