Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/util/pacsort.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/pacsort.c')
-rw-r--r--src/util/pacsort.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/util/pacsort.c b/src/util/pacsort.c
index 665f2180..9d248fad 100644
--- a/src/util/pacsort.c
+++ b/src/util/pacsort.c
@@ -1,7 +1,7 @@
/*
* pacsort.c - a sort utility implementing alpm_pkg_vercmp
*
- * Copyright (c) 2010-2014 Pacman Development Team <pacman-dev@archlinux.org>
+ * Copyright (c) 2010-2015 Pacman Development Team <pacman-dev@archlinux.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@
#include <string.h>
#include <alpm.h>
+#include "util-common.h"
#define DELIM ' '
@@ -69,28 +70,6 @@ static struct options_t {
char delim;
} opts;
-#ifndef HAVE_STRNDUP
-/* A quick and dirty implementation derived from glibc */
-static size_t strnlen(const char *s, size_t max)
-{
- register const char *p;
- for(p = s; *p && max--; ++p);
- return (p - s);
-}
-
-char *strndup(const char *s, size_t n)
-{
- size_t len = strnlen(s, n);
- char *new = (char *) malloc(len + 1);
-
- if(new == NULL)
- return NULL;
-
- new[len] = '\0';
- return (char *)memcpy(new, s, len);
-}
-#endif
-
static struct buffer_t *buffer_new(size_t initial_size)
{
struct buffer_t *buf;
@@ -227,6 +206,7 @@ static struct input_t *input_new(const char *path, int pathlen)
in->data = strndup(path, pathlen);
if(in->data == NULL) {
+ free(in);
return NULL;
}
@@ -398,9 +378,13 @@ static int vercmp(const void *p1, const void *p2)
static char escape_char(const char *string)
{
+ if(!string) {
+ return -1;
+ }
+
const size_t len = strlen(string);
- if(!string || len > 2) {
+ if(len > 2) {
return -1;
}