| |

VerySource

 Forgot password?
 Register
Search
View: 556|Reply: 3

Ask a question about string release?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-27 20:40:02
| Show all posts |Read mode
char * sss = "TEST AAAAAAAAAAAAAAA";
int i = strlen (sss);
char * ch = new char [i];

strcpy (ch, sss);

delete [] ch; // An error will be reported when this sentence is executed

Please ask everyone how this problem is going on.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-23 07:30:02
| Show all posts
int i = strlen (sss) + 1;

Buffer overflow
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-2-23 10:45:02
| Show all posts
Thank you, but why is this?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-26 10:45:01
| Show all posts
When strcpy copy string, including NULL end
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list