[Skiboot] [PATCH] Remove unused scanf and variants

Stewart Smith stewart at linux.vnet.ibm.com
Fri Nov 13 12:03:16 AEDT 2015


We don't use scanf at all, so solve the bugs found by static analysis
by just removing it.

Signed-off-by: Stewart Smith <stewart at linux.vnet.ibm.com>
---
 libc/stdio/Makefile.inc |   6 +-
 libc/stdio/fscanf.c     |  26 -----
 libc/stdio/scanf.c      |  26 -----
 libc/stdio/vfscanf.c    | 269 ------------------------------------------------
 libc/stdio/vsscanf.c    | 131 -----------------------
 5 files changed, 3 insertions(+), 455 deletions(-)
 delete mode 100644 libc/stdio/fscanf.c
 delete mode 100644 libc/stdio/scanf.c
 delete mode 100644 libc/stdio/vfscanf.c
 delete mode 100644 libc/stdio/vsscanf.c

diff --git a/libc/stdio/Makefile.inc b/libc/stdio/Makefile.inc
index 7c3cb08973fe..d2aee0f518f7 100644
--- a/libc/stdio/Makefile.inc
+++ b/libc/stdio/Makefile.inc
@@ -13,9 +13,9 @@
 
 SUBDIRS += $(LIBCDIR)/stdio
 
-STDIO_OBJS = fscanf.o vfprintf.o vsnprintf.o fprintf.o \
-	     setvbuf.o fputc.o puts.o fputs.o putchar.o scanf.o \
-	     stdchnls.o vfscanf.o vsscanf.o fileno.o snprintf.o
+STDIO_OBJS = vfprintf.o vsnprintf.o fprintf.o \
+	     setvbuf.o fputc.o puts.o fputs.o putchar.o \
+	     stdchnls.o fileno.o snprintf.o
 
 STDIO = $(LIBCDIR)/stdio/built-in.o
 $(STDIO): $(STDIO_OBJS:%=$(LIBCDIR)/stdio/%)
diff --git a/libc/stdio/fscanf.c b/libc/stdio/fscanf.c
deleted file mode 100644
index 321b1630a88b..000000000000
--- a/libc/stdio/fscanf.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials
- * are made available under the terms of the BSD License
- * which accompanies this distribution, and is available at
- * http://www.opensource.org/licenses/bsd-license.php
- *
- * Contributors:
- *     IBM Corporation - initial implementation
- *****************************************************************************/
-
-#include <stdio.h>
-
-int
-fscanf(FILE *stream, const char *fmt, ...)
-{
-	int count;
-	va_list ap;
-
-	va_start(ap, fmt);
-	count = vfscanf(stream, fmt, ap);
-	va_end(ap);
-
-	return count;
-}
diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c
deleted file mode 100644
index 96b639980eeb..000000000000
--- a/libc/stdio/scanf.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials
- * are made available under the terms of the BSD License
- * which accompanies this distribution, and is available at
- * http://www.opensource.org/licenses/bsd-license.php
- *
- * Contributors:
- *     IBM Corporation - initial implementation
- *****************************************************************************/
-
-#include <stdio.h>
-
-int
-scanf(const char *fmt, ...)
-{
-	int count;
-	va_list ap;
-
-	va_start(ap, fmt);
-	count = vfscanf(stdin, fmt, ap);
-	va_end(ap);
-
-	return count;
-}
diff --git a/libc/stdio/vfscanf.c b/libc/stdio/vfscanf.c
deleted file mode 100644
index 85ca8be5d8df..000000000000
--- a/libc/stdio/vfscanf.c
+++ /dev/null
@@ -1,269 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials
- * are made available under the terms of the BSD License
- * which accompanies this distribution, and is available at
- * http://www.opensource.org/licenses/bsd-license.php
- *
- * Contributors:
- *     IBM Corporation - initial implementation
- *****************************************************************************/
-
-#include "string.h"
-#include "ctype.h"
-#include "stdlib.h"
-#include "stdio.h"
-#include "unistd.h"
-
-
-static int
-_getc(FILE * stream)
-{
-	int count;
-	char c;
-
-	if (stream->mode == _IONBF || stream->buf == NULL) {
-		if (read(stream->fd, &c, 1) == 1)
-			return (int) c;
-		else
-			return EOF;
-	}
-
-	if (stream->pos == 0 || stream->pos >= BUFSIZ ||
-	    stream->buf[stream->pos] == '\0') {
-		count = read(stream->fd, stream->buf, BUFSIZ);
-		if (count < 0)
-			count = 0;
-		if (count < BUFSIZ)
-			stream->buf[count] = '\0';
-		stream->pos = 0;
-	}
-
-	return stream->buf[stream->pos++];
-}
-
-static void
-_ungetc(int ch, FILE * stream)
-{
-	if (stream->mode != _IONBF && stream->pos > 0) {
-		if (stream->pos < BUFSIZ)
-			stream->buf[stream->pos] = ch;
-		stream->pos--;
-	}
-}
-
-static int
-_is_voidage(int ch)
-{
-	if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' || ch == '\0')
-		return 1;
-	else
-		return 0;
-}
-
-
-static int
-_scanf(FILE * stream, const char *fmt, va_list * ap)
-{
-	int i = 0;
-	int length = 0;
-
-	fmt++;
-
-	while (*fmt != '\0') {
-
-		char tbuf[256];
-		char ch;
-
-		switch (*fmt) {
-		case 'd':
-		case 'i':
-			ch = _getc(stream);
-			if (length == 0) {
-				while (!_is_voidage(ch) && isdigit(ch)) {
-					tbuf[i] = ch;
-					ch = _getc(stream);
-					i++;
-				}
-			} else {
-				while (!_is_voidage(ch) && i < length
-				       && isdigit(ch)) {
-					tbuf[i] = ch;
-					ch = _getc(stream);
-					i++;
-				}
-			}
-			/* We tried to understand what this is good for...
-			 * but we did not. We know for sure that it does not
-			 * work on SLOF if this is active. */
-			/* _ungetc(ch, stream); */
-			tbuf[i] = '\0';
-
-			/* ch = _getc(stream); */
-			if (!_is_voidage(ch))
-				_ungetc(ch, stream);
-
-			if (strlen(tbuf) == 0)
-				return 0;
-
-			*(va_arg(*ap, int *)) = strtol(tbuf, NULL, 10);
-			break;
-		case 'X':
-		case 'x':
-			ch = _getc(stream);
-			if (length == 0) {
-				while (!_is_voidage(ch) && isxdigit(ch)) {
-					tbuf[i] = ch;
-					ch = _getc(stream);
-					i++;
-				}
-			} else {
-				while (!_is_voidage(ch) && i < length
-				       && isxdigit(ch)) {
-					tbuf[i] = ch;
-					ch = _getc(stream);
-					i++;
-				}
-			}
-			/* _ungetc(ch, stream); */
-			tbuf[i] = '\0';
-
-			/* ch = _getc(stream); */
-			if (!_is_voidage(ch))
-				_ungetc(ch, stream);
-
-			if (strlen(tbuf) == 0)
-				return 0;
-
-			*(va_arg(*ap, int *)) = strtol(tbuf, NULL, 16);
-			break;
-		case 'O':
-		case 'o':
-			ch = _getc(stream);
-			if (length == 0) {
-				while (!_is_voidage(ch)
-				       && !(ch < '0' || ch > '7')) {
-					tbuf[i] = ch;
-					ch = _getc(stream);
-					i++;
-				}
-			} else {
-				while (!_is_voidage(ch) && i < length
-				       && !(ch < '0' || ch > '7')) {
-					tbuf[i] = ch;
-					ch = _getc(stream);
-					i++;
-				}
-			}
-			/* _ungetc(ch, stream); */
-			tbuf[i] = '\0';
-
-			/* ch = _getc(stream); */
-			if (!_is_voidage(ch))
-				_ungetc(ch, stream);
-
-			if (strlen(tbuf) == 0)
-				return 0;
-
-			*(va_arg(*ap, int *)) = strtol(tbuf, NULL, 8);
-			break;
-		case 'c':
-			ch = _getc(stream);
-			while (_is_voidage(ch))
-				ch = _getc(stream);
-
-			*(va_arg(*ap, char *)) = ch;
-
-			ch = _getc(stream);
-			if (!_is_voidage(ch))
-				_ungetc(ch, stream);
-
-			break;
-		case 's':
-			ch = _getc(stream);
-			if (length == 0) {
-				while (!_is_voidage(ch)) {
-					tbuf[i] = ch;
-					ch = _getc(stream);
-					i++;
-				}
-			} else {
-				while (!_is_voidage(ch) && i < length) {
-					tbuf[i] = ch;
-					ch = _getc(stream);
-					i++;
-				}
-			}
-			/* _ungetc(ch, stream); */
-			tbuf[i] = '\0';
-
-			/* ch = _getc(stream); */
-			if (!_is_voidage(ch))
-				_ungetc(ch, stream);
-
-			strcpy(va_arg(*ap, char *), tbuf);
-			break;
-		default:
-			if (*fmt >= '0' && *fmt <= '9')
-				length += *fmt - '0';
-			break;
-		}
-		fmt++;
-	}
-
-	return 1;
-}
-
-
-
-int
-vfscanf(FILE * stream, const char *fmt, va_list ap)
-{
-	int args = 0;
-
-	while (*fmt != '\0') {
-
-		if (*fmt == '%') {
-
-			char formstr[20];
-			int i = 0;
-
-			do {
-				formstr[i] = *fmt;
-				fmt++;
-				i++;
-			} while (!
-				 (*fmt == 'd' || *fmt == 'i' || *fmt == 'x'
-				  || *fmt == 'X' || *fmt == 'p' || *fmt == 'c'
-				  || *fmt == 's' || *fmt == '%' || *fmt == 'O'
-				  || *fmt == 'o'));
-			formstr[i++] = *fmt;
-			formstr[i] = '\0';
-			if (*fmt != '%') {
-				if (_scanf(stream, formstr, &ap) <= 0)
-					return args;
-				else
-					args++;
-			}
-
-		}
-
-		fmt++;
-
-	}
-
-	return args;
-}
-
-int
-getc(FILE * stream)
-{
-	return _getc(stream);
-}
-
-int
-getchar(void)
-{
-	return _getc(stdin);
-}
diff --git a/libc/stdio/vsscanf.c b/libc/stdio/vsscanf.c
deleted file mode 100644
index b9603e98ba8e..000000000000
--- a/libc/stdio/vsscanf.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials
- * are made available under the terms of the BSD License
- * which accompanies this distribution, and is available at
- * http://www.opensource.org/licenses/bsd-license.php
- *
- * Contributors:
- *     IBM Corporation - initial implementation
- *****************************************************************************/
-
-#include "stdio.h"
-#include "stdlib.h"
-#include "string.h"
-
-
-static void
-_scanf(const char **buffer, const char *fmt, va_list *ap)
-{
-	int i;
-	int length = 0;
-
-	fmt++;	
-
-	while(*fmt != '\0') {
-		
-		char tbuf[256];
-
-		switch(*fmt) {
-			case 'd':
-			case 'i':
-				if(length == 0) length = 256;
-				
-				for(i = 0; **buffer != ' ' && **buffer != '\t' && **buffer != '\n' && i < length; i++) {
-					tbuf[i] = **buffer;
-					*buffer += 1;
-				}
-				tbuf[i] = '\0';
-
-				*(va_arg(*ap, int *)) = strtol(tbuf, NULL, 10);
-				break;
-			case 'X':
-			case 'x':
-				if(length == 0) length = 256;
-				
-				for(i = 0; **buffer != ' ' && **buffer != '\t' && **buffer != '\n' && i < length; i++) {
-					tbuf[i] = **buffer;
-					*buffer += 1;
-				}
-				tbuf[i] = '\0';
-					
-				*(va_arg(*ap, int *)) = strtol(tbuf, NULL, 16);
-				break;
-			case 'O':
-			case 'o':
-				if(length == 0) length = 256;
-				
-				for(i = 0; **buffer != ' ' && **buffer != '\t' && **buffer != '\n' && i < length; i++) {
-					tbuf[i] = **buffer;
-					*buffer += 1;
-				}
-				tbuf[i] = '\0';
-
-				*(va_arg(*ap, int *)) = strtol(tbuf, NULL, 8);
-				break;
-			case 'c':
-				*(va_arg(*ap, char *)) = **buffer;
-				*buffer += 1;
-				if(length > 1)
-					for(i = 1; i < length; i++)
-						*buffer += 1;
-				break;
-			case 's':
-				if(length == 0) length = 256;
-				
-				for(i = 0; **buffer != ' ' && **buffer != '\t' && **buffer != '\n' && i < length; i++) {
-					tbuf[i] = **buffer;
-					*buffer += 1;
-				}
-
-				tbuf[i] = '\0';
-
-				strcpy(va_arg(*ap, char *), tbuf);
-				break;
-			default:
-				if(*fmt >= '0' && *fmt <= '9') 
-					length += *fmt - '0';
-				break;
-		}
-		fmt++;
-	}
-
-}
-
-
-int
-vsscanf(const char *buffer, const char *fmt, va_list ap)
-{
-
-	while(*fmt != '\0') {
-		
-		if(*fmt == '%') {
-			
-			char formstr[20];
-			int i=0;
-			
-			do {
-				formstr[i] = *fmt;
-				fmt++;
-				i++;
-			} while(!(*fmt == 'd' || *fmt == 'i' || *fmt == 'x' || *fmt == 'X'
-						|| *fmt == 'p' || *fmt == 'c' || *fmt == 's' || *fmt == '%'
-						|| *fmt == 'O' || *fmt == 'o' )); 
-			formstr[i++] = *fmt;
-			formstr[i] = '\0';
-			if(*fmt != '%') {
-				while(*buffer == ' ' || *buffer == '\t' || *buffer == '\n')
-					buffer++;
-				_scanf(&buffer, formstr, &ap);
-			}
-
-		} 
-
-		fmt++;
-
-	}
-
-	return 0;
-}
-
-- 
2.1.4



More information about the Skiboot mailing list