[liblinear] 105/123: Added patch 0006-Improve-option-parsing

Christian Kastner chrisk-guest at moszumanska.debian.org
Tue Aug 26 03:42:14 UTC 2014


This is an automated email from the git hooks/post-receive script.

chrisk-guest pushed a commit to branch master
in repository liblinear.

commit e89e113e825af1a48c9bd184bdb5b5fd0660465e
Author: Christian Kastner <debian at kvr.at>
Date:   Tue Feb 18 18:02:15 2014 +0100

    Added patch 0006-Improve-option-parsing
---
 ...uild-shared-and-static-libraries-programs.patch |  57 +++----
 debian/patches/0005-Documentation-fix.patch        |  15 +-
 debian/patches/0006-Improve-option-parsing.patch   | 184 +++++++++++++++++++++
 debian/patches/series                              |   1 +
 4 files changed, 219 insertions(+), 38 deletions(-)

diff --git a/debian/patches/0001-Properly-build-shared-and-static-libraries-programs.patch b/debian/patches/0001-Properly-build-shared-and-static-libraries-programs.patch
index f095ee5..cafe456 100644
--- a/debian/patches/0001-Properly-build-shared-and-static-libraries-programs.patch
+++ b/debian/patches/0001-Properly-build-shared-and-static-libraries-programs.patch
@@ -1,6 +1,6 @@
 From: Christian Kastner <debian at kvr.at>
 Date: Fri, 9 Jul 2010 18:09:09 +0200
-Subject: [PATCH] Properly build shared and static libraries, programs
+Subject: Properly build shared and static libraries, programs
 
 Modify upstream's Makefile to properly build shared and static libraries,
 link upstream's programs to the shared libraries.
@@ -8,59 +8,52 @@ link upstream's programs to the shared libraries.
 Forwarded: not-needed
 Last-Update: 2011-04-11
 ---
- Makefile |   50 ++++++++++++++++++++++++++++++++------------------
- 1 files changed, 32 insertions(+), 18 deletions(-)
+ Makefile | 46 ++++++++++++++++++++++++++++++----------------
+ 1 file changed, 30 insertions(+), 16 deletions(-)
 
-Index: liblinear-1.8.orig/Makefile
-===================================================================
---- liblinear-1.8.orig.orig/Makefile	2011-04-05 14:14:49.000000000 +0200
-+++ liblinear-1.8.orig/Makefile	2011-04-05 14:23:19.804010092 +0200
+diff --git a/Makefile b/Makefile
+index 503a760..a2082d5 100644
+--- a/Makefile
++++ b/Makefile
 @@ -1,27 +1,41 @@
  CXX ?= g++
  CC ?= gcc
 -CFLAGS = -Wall -Wconversion -O3 -fPIC
 -LIBS =
 -SHVER = 1
--
--all: train predict
--
--lib: linear.o tron.o
--	$(CXX) -shared -dynamiclib linear.o tron.o -o liblinear.so.$(SHVER)
--
--train: tron.o linear.o train.c
--	$(CXX) $(CFLAGS) -o train train.c tron.o linear.o $(LIBS)
--
--predict: tron.o linear.o predict.c
--	$(CXX) $(CFLAGS) -o predict predict.c tron.o linear.o $(LIBS)
--
--tron.o: tron.cpp tron.h
--	$(CXX) $(CFLAGS) -c -o tron.o tron.cpp
--
--linear.o: linear.cpp linear.h
--	$(CXX) $(CFLAGS) -c -o linear.o linear.cpp
--
 +CFLAGS += $(CPPFLAGS)
 +LDFLAGS += -L.
 +LIBS +=
-+
+ 
+-all: train predict
 +LIB_CFLAGS += $(CFLAGS) -fPIC
 +LIB_LDFLAGS += $(LDFLAGS)
 +LIB_LIBS += $(LIBS) -lblas
-+
+ 
+-lib: linear.o tron.o
+-	$(CXX) -shared -dynamiclib linear.o tron.o -o liblinear.so.$(SHVER)
 +PROG_CFLAGS += $(CFLAGS)
 +PROG_LDFLAGS += $(LDFLAGS)
 +PROG_LIBS += $(LIBS) -llinear
-+
+ 
+-train: tron.o linear.o train.c
+-	$(CXX) $(CFLAGS) -o train train.c tron.o linear.o $(LIBS)
 +LVER ?= 0
 +LSUBVER ?= 0
 +LIBFILE = liblinear.so.$(LVER).$(LSUBVER)
-+
-+
+ 
+-predict: tron.o linear.o predict.c
+-	$(CXX) $(CFLAGS) -o predict predict.c tron.o linear.o $(LIBS)
+ 
+-tron.o: tron.cpp tron.h
+-	$(CXX) $(CFLAGS) -c -o tron.o tron.cpp
 +all: liblinear-train liblinear-predict liblinear.a
-+
+ 
+-linear.o: linear.cpp linear.h
+-	$(CXX) $(CFLAGS) -c -o linear.o linear.cpp
 +liblinear-train: train.c $(LIBFILE)
 +	$(CXX) $(PROG_CFLAGS) $(PROG_LDFLAGS) -o $@ train.c $(PROG_LIBS)
-+
+ 
 +liblinear-predict: predict.c $(LIBFILE)
 +	$(CXX) $(PROG_CFLAGS) $(PROG_LDFLAGS) -o $@ predict.c $(PROG_LIBS)
 +
diff --git a/debian/patches/0005-Documentation-fix.patch b/debian/patches/0005-Documentation-fix.patch
index 940880d..c406579 100644
--- a/debian/patches/0005-Documentation-fix.patch
+++ b/debian/patches/0005-Documentation-fix.patch
@@ -1,17 +1,20 @@
 From: Christian Kastner <debian at kvr.at>
 Date: Mon, 11 Apr 2011 17:25:04 +0200
-Subject: Documentation fix 
+Subject: Documentation fix
 
 Documented formula does not match train.c and matlab/train.c
 
 Forwarded: yes 
 Last-Update: 2011-04-11
+---
+ README | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
 
-Index: liblinear-1.8+dfsg/README
-===================================================================
---- liblinear-1.8+dfsg.orig/README	2011-04-11 17:28:39.688001268 +0200
-+++ liblinear-1.8+dfsg/README	2011-04-11 17:29:04.567996946 +0200
-@@ -114,7 +114,7 @@
+diff --git a/README b/README
+index 4e45c2e..357c469 100644
+--- a/README
++++ b/README
+@@ -114,7 +114,7 @@ options:
  	-s 1, 3, 4 and 7
  		Dual maximal violation <= eps; similar to libsvm (default 0.1)
  	-s 5 and 6
diff --git a/debian/patches/0006-Improve-option-parsing.patch b/debian/patches/0006-Improve-option-parsing.patch
new file mode 100644
index 0000000..7e161fd
--- /dev/null
+++ b/debian/patches/0006-Improve-option-parsing.patch
@@ -0,0 +1,184 @@
+From: Christian Kastner <debian at kvr.at>
+Date: Tue, 18 Feb 2014 17:57:16 +0100
+Subject: Improve option parsing
+
+Detect errors when parsing numeric arguments, check for the right number of
+arguments, and use optarg(3) if possible.
+
+Bug-Debian: http://bugs.debian.org/716115
+Forwarded: yes
+Last-Update: 2014-02-19
+---
+ predict.c | 45 ++++++++++++++++++++++++---------------------
+ train.c   | 44 +++++++++++++++++++++++++++++++++++++-------
+ 2 files changed, 61 insertions(+), 28 deletions(-)
+
+diff --git a/predict.c b/predict.c
+index 0b4be97..831275f 100644
+--- a/predict.c
++++ b/predict.c
+@@ -3,6 +3,7 @@
+ #include <stdlib.h>
+ #include <string.h>
+ #include <errno.h>
++#include <unistd.h>
+ #include "linear.h"
+ 
+ struct feature_node *x;
+@@ -164,45 +165,47 @@ void exit_with_help()
+ int main(int argc, char **argv)
+ {
+ 	FILE *input, *output;
+-	int i;
++	int opt;
+ 
+ 	// parse options
+-	for(i=1;i<argc;i++)
+-	{
+-		if(argv[i][0] != '-') break;
+-		++i;
+-		switch(argv[i-1][1])
+-		{
+-			case 'b':
+-				flag_predict_probability = atoi(argv[i]);
+-				break;
+-
+-			default:
+-				fprintf(stderr,"unknown option: -%c\n", argv[i-1][1]);
++	while ((opt = getopt(argc, argv, "b:")) != -1) {
++		switch(opt) {
++		case 'b':
++			if (strcmp(optarg, "0") == 0) {
++				flag_predict_probability = 0;
++			} else if (strcmp(optarg, "1") == 0) {
++				flag_predict_probability = 1;
++			} else {
+ 				exit_with_help();
+-				break;
++			}
++			break;
++		default:
++			exit_with_help();
++			break;
+ 		}
+ 	}
+-	if(i>=argc)
++
++	// Besides options, we expect exactly 3 arguments
++	if(optind+3 != argc)
+ 		exit_with_help();
+ 
+-	input = fopen(argv[i],"r");
++	input = fopen(argv[optind],"r");
+ 	if(input == NULL)
+ 	{
+-		fprintf(stderr,"can't open input file %s\n",argv[i]);
++		fprintf(stderr,"can't open input file %s\n",argv[optind]);
+ 		exit(1);
+ 	}
+ 
+-	output = fopen(argv[i+2],"w");
++	output = fopen(argv[optind+2],"w");
+ 	if(output == NULL)
+ 	{
+-		fprintf(stderr,"can't open output file %s\n",argv[i+2]);
++		fprintf(stderr,"can't open output file %s\n",argv[optind+2]);
+ 		exit(1);
+ 	}
+ 
+-	if((model_=load_model(argv[i+1]))==0)
++	if((model_=load_model(argv[optind+1]))==0)
+ 	{
+-		fprintf(stderr,"can't open model file %s\n",argv[i+1]);
++		fprintf(stderr,"can't open model file %s\n",argv[optind+1]);
+ 		exit(1);
+ 	}
+ 
+diff --git a/train.c b/train.c
+index 4920313..35f51d0 100644
+--- a/train.c
++++ b/train.c
+@@ -4,6 +4,7 @@
+ #include <string.h>
+ #include <ctype.h>
+ #include <errno.h>
++#include <limits.h>
+ #include "linear.h"
+ #define Malloc(type,n) (type *)malloc((n)*sizeof(type))
+ #define INF HUGE_VAL
+@@ -49,6 +50,34 @@ void exit_input_error(int line_num)
+ 	exit(1);
+ }
+ 
++static long strtol_or_exit(const char *str) {
++	errno = 0;
++	char *endptr;
++	long val = strtol(str, &endptr, 10);
++
++	if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) || (errno != 0 && val == 0)) {
++		perror("error converting %s to int:");
++		exit_with_help();
++	} else if (*endptr != '\0') {
++		exit_with_help();
++	}
++	return val;
++}
++
++static float strtof_or_exit(const char *str) {
++	errno = 0;
++	char *endptr;
++	float val = strtol(str, &endptr, 10);
++
++	if ((errno == ERANGE && (val == HUGE_VALF || val == HUGE_VALL)) || (errno != 0 && val == 0.0)) {
++		perror("error converting %s to float:");
++		exit_with_help();
++	} else if (*endptr != '\0') {
++		exit_with_help();
++	}
++	return val;
++}
++
+ static char *line = NULL;
+ static int max_line_len;
+ 
+@@ -161,32 +190,33 @@ void parse_command_line(int argc, char **argv, char *input_file_name, char *mode
+ 		switch(argv[i-1][1])
+ 		{
+ 			case 's':
+-				param.solver_type = atoi(argv[i]);
++				param.solver_type = strtol_or_exit(argv[i]);
+ 				break;
+ 
+ 			case 'c':
+-				param.C = atof(argv[i]);
++				param.C = strtof_or_exit(argv[i]);
+ 				break;
+ 
+ 			case 'e':
+-				param.eps = atof(argv[i]);
++				param.eps = strtof_or_exit(argv[i]);
+ 				break;
+ 
+ 			case 'B':
+-				bias = atof(argv[i]);
++				bias = strtof_or_exit(argv[i]);
+ 				break;
+ 
+ 			case 'w':
+ 				++param.nr_weight;
+ 				param.weight_label = (int *) realloc(param.weight_label,sizeof(int)*param.nr_weight);
+ 				param.weight = (double *) realloc(param.weight,sizeof(double)*param.nr_weight);
+-				param.weight_label[param.nr_weight-1] = atoi(&argv[i-1][2]);
+-				param.weight[param.nr_weight-1] = atof(argv[i]);
++				param.weight_label[param.nr_weight-1] = strtol_or_exit(&argv[i-1][2]);
++				param.weight[param.nr_weight-1] =
++					strtof_or_exit(argv[i]);
+ 				break;
+ 
+ 			case 'v':
+ 				flag_cross_validation = 1;
+-				nr_fold = atoi(argv[i]);
++				nr_fold = strtol_or_exit(argv[i]);
+ 				if(nr_fold < 2)
+ 				{
+ 					fprintf(stderr,"n-fold cross validation: n must >= 2\n");
diff --git a/debian/patches/series b/debian/patches/series
index 7772076..b7d1b03 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,3 @@
 0001-Properly-build-shared-and-static-libraries-programs.patch
 0005-Documentation-fix.patch
+0006-Improve-option-parsing.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/liblinear.git



More information about the debian-science-commits mailing list