Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Administrator
Public Cpp Test
Commits
2a291a73
Commit
2a291a73
authored
Oct 23, 2023
by
shengnan hu
Browse files
main
parents
Changes
638
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
394 additions
and
0 deletions
+394
-0
BM-GJB8114-2013/R-1-6-14/R-1-6-14-good.cpp
BM-GJB8114-2013/R-1-6-14/R-1-6-14-good.cpp
+11
-0
BM-GJB8114-2013/R-1-6-15/R-1-6-15-bad.c
BM-GJB8114-2013/R-1-6-15/R-1-6-15-bad.c
+11
-0
BM-GJB8114-2013/R-1-6-15/R-1-6-15-bad.cpp
BM-GJB8114-2013/R-1-6-15/R-1-6-15-bad.cpp
+11
-0
BM-GJB8114-2013/R-1-6-15/R-1-6-15-good.c
BM-GJB8114-2013/R-1-6-15/R-1-6-15-good.c
+11
-0
BM-GJB8114-2013/R-1-6-15/R-1-6-15-good.cpp
BM-GJB8114-2013/R-1-6-15/R-1-6-15-good.cpp
+11
-0
BM-GJB8114-2013/R-1-6-16/R-1-6-16-bad.c
BM-GJB8114-2013/R-1-6-16/R-1-6-16-bad.c
+26
-0
BM-GJB8114-2013/R-1-6-16/R-1-6-16-bad.cpp
BM-GJB8114-2013/R-1-6-16/R-1-6-16-bad.cpp
+26
-0
BM-GJB8114-2013/R-1-6-17/R-1-6-17-bad.c
BM-GJB8114-2013/R-1-6-17/R-1-6-17-bad.c
+34
-0
BM-GJB8114-2013/R-1-6-17/R-1-6-17-bad.cpp
BM-GJB8114-2013/R-1-6-17/R-1-6-17-bad.cpp
+34
-0
BM-GJB8114-2013/R-1-6-17/R-1-6-17-good.c
BM-GJB8114-2013/R-1-6-17/R-1-6-17-good.c
+35
-0
BM-GJB8114-2013/R-1-6-17/R-1-6-17-good.cpp
BM-GJB8114-2013/R-1-6-17/R-1-6-17-good.cpp
+35
-0
BM-GJB8114-2013/R-1-6-18/R-1-6-18-bad.c
BM-GJB8114-2013/R-1-6-18/R-1-6-18-bad.c
+21
-0
BM-GJB8114-2013/R-1-6-18/R-1-6-18-bad.cpp
BM-GJB8114-2013/R-1-6-18/R-1-6-18-bad.cpp
+21
-0
BM-GJB8114-2013/R-1-6-18/R-1-6-18-good.c
BM-GJB8114-2013/R-1-6-18/R-1-6-18-good.c
+21
-0
BM-GJB8114-2013/R-1-6-18/R-1-6-18-good.cpp
BM-GJB8114-2013/R-1-6-18/R-1-6-18-good.cpp
+21
-0
BM-GJB8114-2013/R-1-6-19/R-1-6-19-bad.c
BM-GJB8114-2013/R-1-6-19/R-1-6-19-bad.c
+14
-0
BM-GJB8114-2013/R-1-6-19/R-1-6-19-bad.cpp
BM-GJB8114-2013/R-1-6-19/R-1-6-19-bad.cpp
+14
-0
BM-GJB8114-2013/R-1-6-19/R-1-6-19-good.c
BM-GJB8114-2013/R-1-6-19/R-1-6-19-good.c
+14
-0
BM-GJB8114-2013/R-1-6-19/R-1-6-19-good.cpp
BM-GJB8114-2013/R-1-6-19/R-1-6-19-good.cpp
+14
-0
BM-GJB8114-2013/R-1-6-2/R-1-6-2-bad.c
BM-GJB8114-2013/R-1-6-2/R-1-6-2-bad.c
+9
-0
No files found.
BM-GJB8114-2013/R-1-6-14/R-1-6-14-good.cpp
0 → 100644
View file @
2a291a73
#include <string.h>
int
main
(
void
)
{
int
src
[
2
]
=
{
1
,
2
};
int
des
[
4
]
=
{
0
,
0
,
0
,
0
};
memcpy
(
des
,
src
,
sizeof
(
src
)
);
//遵循1
return
(
0
);
}
BM-GJB8114-2013/R-1-6-15/R-1-6-15-bad.c
0 → 100644
View file @
2a291a73
#include <string.h>
int
main
(
void
)
{
int
src
[
4
]
=
{
1
,
2
,
3
,
4
};
int
des
[
2
]
=
{
0
,
0
};
memcpy
(
des
,
src
,
sizeof
(
src
)
);
//违背1
return
(
0
);
}
BM-GJB8114-2013/R-1-6-15/R-1-6-15-bad.cpp
0 → 100644
View file @
2a291a73
#include <string.h>
int
main
(
void
)
{
int
src
[
4
]
=
{
1
,
2
,
3
,
4
};
int
des
[
2
]
=
{
0
,
0
};
memcpy
(
des
,
src
,
sizeof
(
src
)
);
//违背1
return
(
0
);
}
BM-GJB8114-2013/R-1-6-15/R-1-6-15-good.c
0 → 100644
View file @
2a291a73
#include <string.h>
int
main
(
void
)
{
int
src
[
4
]
=
{
1
,
2
,
3
,
4
};
int
des
[
2
]
=
{
0
,
0
};
memcpy
(
des
,
src
,
sizeof
(
des
)
);
//遵循1
return
(
0
);
}
BM-GJB8114-2013/R-1-6-15/R-1-6-15-good.cpp
0 → 100644
View file @
2a291a73
#include <string.h>
int
main
(
void
)
{
int
src
[
4
]
=
{
1
,
2
,
3
,
4
};
int
des
[
2
]
=
{
0
,
0
};
memcpy
(
des
,
src
,
sizeof
(
des
)
);
//遵循1
return
(
0
);
}
BM-GJB8114-2013/R-1-6-16/R-1-6-16-bad.c
0 → 100644
View file @
2a291a73
#include <malloc.h>
#include <stdlib.h>
int
main
(
void
)
{
int
*
x
=
(
int
*
)
malloc
(
sizeof
(
int
)
);
int
y
;
if
(
NULL
!=
x
)
{
*
x
=
1
;
//......
free
(
x
);
x
=
NULL
;
}
else
{
return
(
-
1
);
}
y
=
(
*
x
);
//违背1
return
(
0
);
}
BM-GJB8114-2013/R-1-6-16/R-1-6-16-bad.cpp
0 → 100644
View file @
2a291a73
#include <malloc.h>
#include <stdlib.h>
int
main
(
void
)
{
int
*
x
=
(
int
*
)
malloc
(
sizeof
(
int
)
);
int
y
;
if
(
NULL
!=
x
)
{
*
x
=
1
;
//......
free
(
x
);
x
=
NULL
;
}
else
{
return
(
-
1
);
}
y
=
(
*
x
);
//违背1
return
(
0
);
}
BM-GJB8114-2013/R-1-6-17/R-1-6-17-bad.c
0 → 100644
View file @
2a291a73
#include <malloc.h>
#include <stdlib.h>
int
fun
(
void
);
int
main
(
void
)
{
int
i
;
i
=
fun
(
);
return
(
0
);
}
int
fun
(
void
)
{
int
*
p
=
(
int
*
)
malloc
(
3
*
sizeof
(
int
)
);
if
(
NULL
==
p
)
{
return
(
-
1
);
}
else
{
*
p
=
1
;
p
++
;
*
p
=
2
;
free
(
p
);
//违背1
p
=
NULL
;
}
return
(
0
);
}
BM-GJB8114-2013/R-1-6-17/R-1-6-17-bad.cpp
0 → 100644
View file @
2a291a73
#include <malloc.h>
#include <stdlib.h>
int
fun
(
void
);
int
main
(
void
)
{
int
i
;
i
=
fun
(
);
return
(
0
);
}
int
fun
(
void
)
{
int
*
p
=
(
int
*
)
malloc
(
3
*
sizeof
(
int
)
);
if
(
NULL
==
p
)
{
return
(
-
1
);
}
else
{
*
p
=
1
;
p
++
;
*
p
=
2
;
free
(
p
);
//违背1
p
=
NULL
;
}
return
(
0
);
}
BM-GJB8114-2013/R-1-6-17/R-1-6-17-good.c
0 → 100644
View file @
2a291a73
#include <malloc.h>
#include <stdlib.h>
int
fun
(
void
);
int
main
(
void
)
{
int
i
;
i
=
fun
(
);
return
(
0
);
}
int
fun
(
void
)
{
int
*
p
=
(
int
*
)
malloc
(
3
*
sizeof
(
int
)
);
int
*
pbak
=
p
;
if
(
NULL
==
p
)
{
return
(
-
1
);
}
else
{
*
p
=
1
;
p
++
;
*
p
=
2
;
free
(
pbak
);
//遵循1
p
=
NULL
;
}
return
(
0
);
}
BM-GJB8114-2013/R-1-6-17/R-1-6-17-good.cpp
0 → 100644
View file @
2a291a73
#include <malloc.h>
#include <stdlib.h>
int
fun
(
void
);
int
main
(
void
)
{
int
i
;
i
=
fun
(
);
return
(
0
);
}
int
fun
(
void
)
{
int
*
p
=
(
int
*
)
malloc
(
3
*
sizeof
(
int
)
);
int
*
pbak
=
p
;
if
(
NULL
==
p
)
{
return
(
-
1
);
}
else
{
*
p
=
1
;
p
++
;
*
p
=
2
;
free
(
pbak
);
//遵循1
p
=
NULL
;
}
return
(
0
);
}
BM-GJB8114-2013/R-1-6-18/R-1-6-18-bad.c
0 → 100644
View file @
2a291a73
#include <stdio.h>
int
main
(
void
)
{
char
line
[
5
]
=
{
0
};
printf
(
"Input a string: "
);
if
(
NULL
==
gets
(
line
)
)
//违背1
{
printf
(
"gets error
\n
"
);
return
(
-
1
);
}
else
{
printf
(
"The line entered was: %s
\n
"
,
line
);
}
return
(
0
);
}
BM-GJB8114-2013/R-1-6-18/R-1-6-18-bad.cpp
0 → 100644
View file @
2a291a73
#include <stdio.h>
int
main
(
void
)
{
char
line
[
5
]
=
{
0
};
printf
(
"Input a string: "
);
if
(
NULL
==
gets
(
line
)
)
//违背1
{
printf
(
"gets error
\n
"
);
return
(
-
1
);
}
else
{
printf
(
"The line entered was: %s
\n
"
,
line
);
}
return
(
0
);
}
BM-GJB8114-2013/R-1-6-18/R-1-6-18-good.c
0 → 100644
View file @
2a291a73
#include <stdio.h>
int
main
(
void
)
{
char
line
[
5
]
=
{
0
};
printf
(
"Input a string: "
);
if
(
NULL
==
fgets
(
line
,
5
,
stdin
)
)
//遵循1
{
printf
(
"gets error
\n
"
);
return
(
-
1
);
}
else
{
printf
(
"The line entered was: %s
\n
"
,
line
);
}
return
(
0
);
}
BM-GJB8114-2013/R-1-6-18/R-1-6-18-good.cpp
0 → 100644
View file @
2a291a73
#include <stdio.h>
int
main
(
void
)
{
char
line
[
5
]
=
{
0
};
printf
(
"Input a string: "
);
if
(
NULL
==
fgets
(
line
,
5
,
stdin
)
)
//遵循1
{
printf
(
"gets error
\n
"
);
return
(
-
1
);
}
else
{
printf
(
"The line entered was: %s
\n
"
,
line
);
}
return
(
0
);
}
BM-GJB8114-2013/R-1-6-19/R-1-6-19-bad.c
0 → 100644
View file @
2a291a73
#include <stdio.h>
#include <string.h>
void
main
(
void
)
{
char
string1
[
10
]
=
{
0
};
char
string2
[
10
]
=
{
0
};
strncpy
(
string1
,
"Hello World"
,
11
);
//违背1
strncpy
(
string2
,
"Hello "
,
6
);
strncat
(
string2
,
"world"
,
5
);
//违背2
printf
(
"string1 = %s, string2 = %s
\n
"
,
string1
,
string2
);
}
BM-GJB8114-2013/R-1-6-19/R-1-6-19-bad.cpp
0 → 100644
View file @
2a291a73
#include <stdio.h>
#include <string.h>
void
main
(
void
)
{
char
string1
[
10
]
=
{
0
};
char
string2
[
10
]
=
{
0
};
strncpy
(
string1
,
"Hello World"
,
11
);
//违背1
strncpy
(
string2
,
"Hello "
,
6
);
strncat
(
string2
,
"world"
,
5
);
//违背2
printf
(
"string1 = %s, string2 = %s
\n
"
,
string1
,
string2
);
}
BM-GJB8114-2013/R-1-6-19/R-1-6-19-good.c
0 → 100644
View file @
2a291a73
#include <stdio.h>
#include <string.h>
void
main
(
void
)
{
char
string1
[
12
]
=
{
0
};
char
string2
[
12
]
=
{
0
};
strncpy
(
string1
,
"Hello World"
,
11
);
//遵循1
strncpy
(
string2
,
"Hello "
,
6
);
strncat
(
string2
,
"world"
,
5
);
//遵循2
printf
(
"string1 = %s, string2 = %s
\n
"
,
string1
,
string2
);
}
BM-GJB8114-2013/R-1-6-19/R-1-6-19-good.cpp
0 → 100644
View file @
2a291a73
#include <stdio.h>
#include <string.h>
void
main
(
void
)
{
char
string1
[
12
]
=
{
0
};
char
string2
[
12
]
=
{
0
};
strncpy
(
string1
,
"Hello World"
,
11
);
//遵循1
strncpy
(
string2
,
"Hello "
,
6
);
strncat
(
string2
,
"world"
,
5
);
//遵循2
printf
(
"string1 = %s, string2 = %s
\n
"
,
string1
,
string2
);
}
BM-GJB8114-2013/R-1-6-2/R-1-6-2-bad.c
0 → 100644
View file @
2a291a73
int
main
(
void
)
{
unsigned
char
data1
=
256
;
//违背1
signed
char
data2
=
-
129
;
//违背2
//...
return
(
0
);
}
Prev
1
…
13
14
15
16
17
18
19
20
21
…
32
Next
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