File: no-ending-newline.c

package info (click to toggle)
flawfinder 1.31-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 512 kB
  • ctags: 176
  • sloc: python: 1,405; makefile: 147; ansic: 136; lex: 29
file content (32 lines) | stat: -rw-r--r-- 440 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Test file to show bug in 1.27

#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>

int main()
{
	FILE	*f;
	char	buf[1024], *s;
	int	first;

	first = 1;
	while(fgets(buf, sizeof(buf), stdin) != 0) {
		if(first == 0) {
			printf("\n");
		}
		s = buf;
		while(*s != '\0') {
			if(*s == '\n' || *s == '\r') {
				*s = '\0';
				break;
			}
			s++;
		}
		printf("%s", buf);
		first = 0;
	}
}

/* end with spaces and no \n or \r */