[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r23108 - Extractor/src/main
From: |
gnunet |
Subject: |
[GNUnet-SVN] r23108 - Extractor/src/main |
Date: |
Sat, 4 Aug 2012 23:46:29 +0200 |
Author: grothoff
Date: 2012-08-04 23:46:29 +0200 (Sat, 04 Aug 2012)
New Revision: 23108
Modified:
Extractor/src/main/extract.c
Extractor/src/main/extractor_print.c
Extractor/src/main/iconv.c
Log:
fixing issues with non 0-termianted strings
Modified: Extractor/src/main/extract.c
===================================================================
--- Extractor/src/main/extract.c 2012-08-04 20:31:52 UTC (rev 23107)
+++ Extractor/src/main/extract.c 2012-08-04 21:46:29 UTC (rev 23108)
@@ -108,6 +108,7 @@
*/
#define BORDER 29
+
/**
* Display help text (--help).
*
@@ -296,7 +297,8 @@
cd = iconv_open (nl_langinfo(CODESET), "UTF-8");
if (((iconv_t) -1) != cd)
keyword = iconv_helper (cd,
- data);
+ data,
+ data_len);
else
keyword = strdup (data);
if (NULL != keyword)
@@ -318,8 +320,9 @@
break;
case EXTRACTOR_METAFORMAT_C_STRING:
fprintf (stdout,
- "%s - %s\n",
+ "%s - %.*s\n",
stype,
+ (int) data_len,
data);
break;
default:
@@ -372,10 +375,11 @@
fprintf (stdout,
"%s: ",
gettext(mt));
- cd = iconv_open (nl_langinfo(CODESET), "UTF-8");
+ cd = iconv_open (nl_langinfo (CODESET), "UTF-8");
if (((iconv_t) -1) != cd)
keyword = iconv_helper (cd,
- data);
+ data,
+ data_len);
else
keyword = strdup (data);
if (NULL != keyword)
Modified: Extractor/src/main/extractor_print.c
===================================================================
--- Extractor/src/main/extractor_print.c 2012-08-04 20:31:52 UTC (rev
23107)
+++ Extractor/src/main/extractor_print.c 2012-08-04 21:46:29 UTC (rev
23108)
@@ -17,6 +17,11 @@
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
+/**
+ * @file main/extractor_print.c
+ * @brief convenience functions for printing meta data
+ * @author Christian Grothoff
+ */
#include "platform.h"
#include "extractor.h"
@@ -62,7 +67,7 @@
LOG_STRERROR ("iconv_open");
return 1;
}
- buf = iconv_helper (cd, data);
+ buf = iconv_helper (cd, data, data_len);
if (NULL == buf)
{
LOG_STRERROR ("iconv_helper");
Modified: Extractor/src/main/iconv.c
===================================================================
--- Extractor/src/main/iconv.c 2012-08-04 20:31:52 UTC (rev 23107)
+++ Extractor/src/main/iconv.c 2012-08-04 21:46:29 UTC (rev 23108)
@@ -19,43 +19,53 @@
*/
/**
+ * @file main/iconv.c
+ * @brief convenience functions for character conversion
+ * @author Christian Grothoff
+ */
+
+/**
* Convert the given input using the given converter
* and return as a 0-terminated string.
+ *
+ * @param cd converter to use
+ * @param in input string
+ * @param inSize number of bytes in 'in'
+ * @return NULL on error, otherwise the converted string (to be free'd by
caller)
*/
static char *
-iconv_helper(iconv_t cd,
- const char * in)
+iconv_helper (iconv_t cd,
+ const char *in,
+ size_t inSize)
{
- size_t inSize;
char * buf;
char * ibuf;
const char * i;
size_t outSize;
size_t outLeft;
+ if (inSize > 1024 * 1024)
+ return NULL; /* too big to be meta data */
i = in;
/* reset iconv */
- iconv(cd, NULL, NULL, NULL, NULL);
-
- inSize = strlen(in);
- if (inSize > 1024 * 1024)
- return NULL; /* too big to be meta data */
+ iconv (cd, NULL, NULL, NULL, NULL);
outSize = 4 * inSize + 2;
outLeft = outSize - 2; /* make sure we have 2 0-terminations! */
- buf = malloc(outSize);
- if (buf == NULL)
+ if (NULL == (buf = malloc (outSize)))
return NULL;
ibuf = buf;
- memset(buf, 0, outSize);
- if (iconv(cd,
- (char**) &in,
- &inSize,
- &ibuf,
- &outLeft) == SIZE_MAX)
+ memset (buf, 0, outSize);
+ if (iconv (cd,
+ (char**) &in,
+ &inSize,
+ &ibuf,
+ &outLeft) == SIZE_MAX)
{
/* conversion failed */
- free(buf);
- return strdup(i);
+ free (buf);
+ return strdup (i);
}
return buf;
}
+
+/* end of iconv.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r23108 - Extractor/src/main,
gnunet <=