Commit 2a291a73 authored by shengnan hu's avatar shengnan hu
Browse files

main

parents
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
#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 );
}
int main ( void )
{
unsigned char data1 = 256; //违背1
signed char data2 = -129; //违背2
//...
return ( 0 );
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment