좀 알려주세요~

ybagnes의 이미지

gcc hw3.c -o text

이런식으로 컴파일 하면요~

/tmp/ccOOjIqK.o: In function `parseCommandLine':
/tmp/ccOOjIqK.o(.text+0x4ab): the `gets' function is dangerous and should not be
used.

라고 에러가 떠요.ㅜㅜ
코드는 이렇게 생겼거든요


parseCommandLine(int argc, char* argv[]) {

	/* 중략 */
	char contents[20];
	/* 중략*/
	
	while(quit == 0) { 

		scanf("%c", &com); 

		switch (com) {

		          /* ...중략... */

			case 'A':
			scanf("%d", &number);
			gets(contents);
			append(--number, contents);
			break; 

				}
      }
} 



중간에는 생략했고요~ content[20] 이라고 공간 배정도 해줬는데..
어떻게 해야 에러가 없어지나요?
new5244의 이미지

gets() 함수는 man page 확인해 보시고요

fgets() 함수로 바꿔서 사용하세요...

from saibi

alsong의 이미지

위의 함수는 위험한 함수라더군요.
아마도 버퍼 오버플로우 공격을 당할수 있기 때문에 그런 메시지가
나오지 않았나 싶군요.
man gets

Quote:
Never use gets(). Because it is impossible to tell with-
out knowing the data in advance how many characters gets()
will read, and because gets() will continue to store char-
acters past the end of the buffer, it is extremely danger-
ous to use. It has been used to break computer security.
Use fgets() instead.

It is not advisable to mix calls to input functions from
the stdio library with low - level calls to read() for the
results will be undefined and very probably not what you
want.

인용 뒤에 인용한곳은 어떻게 적나요 ㅡㅡ; 못적겠다

그나저나 백수 언제 탈출하냐... ㅡㅡ; 배고파라.

purewell의 이미지

오류가 아니라 경고입니다.

ㅡ_-) gets 함수는 윗분이 말씀하신 것처럼

버퍼오버플로우 약점을 가질 수 있기 때문에

컴파일 수준에서 경고를 내는 것입니다.

그냥 스따디~ 목적으로 만든 소스라면

gets 쓰셔도 무방합니다.

_____________________________
언제나 맑고픈 샘이가...
http://purewell.biz