GCC uses gets and puts to complain

Source: Internet
Author: User
Tags stdin
The hint that the Linux GCC is not standard C gets,puts function, you can use GCC fgets,fputs to replace gets,puts, the format and change the following: #include "stdio.h"
Main ()
{
Char st[15];
printf ("Input string:\n");
Fgets (St,15,stdin); /*stdin means keyboard input * *
Fputs (st,stdout); /*stdout Standard OUTPUT * *
The reason why GCC does not recommend using the gets and puts functions is that it is clearly written on expert C programming: The Gets function does not check the buffer space, and in fact he cannot check the buffer space, if the caller of the function provides a pointer to the stack, And the gets function reads more characters than the buffer space, and the gets function will happily continue to write the extra characters to the stack, overwriting the original contents of the stack. The early Internet worm took advantage of such a bug The official Manual of C language is strongly recommended to replace the gets function gets (line) completely with the fgets () function; To be replaced by: if (fgets (line,sizeof (line), stdin) ==null) exit (1); This will not overwrite important areas of the stack because others are running the program but Ansic did not remove gets from the standard.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.