summaryrefslogtreecommitdiff
path: root/src/encoding.c
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2015-01-02 20:23:27 +0000
committer <>2015-02-03 17:27:18 +0000
commit670c2bbcffe873a2b8589ed140c12e7923ef20c0 (patch)
tree41044880e826d60621a2d636ed71283de5e0e291 /src/encoding.c
parent3b49db406667ee7189b9ea69b9d9e0bdcc43c5b7 (diff)
downloadfile-670c2bbcffe873a2b8589ed140c12e7923ef20c0.tar.gz
Imported from /home/lorry/working-area/delta_file/file-5.22.tar.gz.file-5.22
Diffstat (limited to 'src/encoding.c')
-rw-r--r--src/encoding.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/encoding.c b/src/encoding.c
index dee57a6..c1b23cc 100644
--- a/src/encoding.c
+++ b/src/encoding.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: encoding.c,v 1.7 2012/01/24 19:02:02 christos Exp $")
+FILE_RCSID("@(#)$File: encoding.c,v 1.10 2014/09/11 12:08:52 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -72,13 +72,17 @@ file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, uni
unsigned char *nbuf = NULL;
*type = "text";
- mlen = (nbytes + 1) * sizeof(nbuf[0]);
- if ((nbuf = CAST(unsigned char *, calloc((size_t)1, mlen))) == NULL) {
+ *ulen = 0;
+ *code = "unknown";
+ *code_mime = "binary";
+
+ mlen = (nbytes + 1) * sizeof((*ubuf)[0]);
+ if ((*ubuf = CAST(unichar *, calloc((size_t)1, mlen))) == NULL) {
file_oomem(ms, mlen);
goto done;
}
- mlen = (nbytes + 1) * sizeof((*ubuf)[0]);
- if ((*ubuf = CAST(unichar *, calloc((size_t)1, mlen))) == NULL) {
+ mlen = (nbytes + 1) * sizeof(nbuf[0]);
+ if ((nbuf = CAST(unsigned char *, calloc((size_t)1, mlen))) == NULL) {
file_oomem(ms, mlen);
goto done;
}
@@ -93,7 +97,6 @@ file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, uni
*code_mime = "utf-8";
} else if (file_looks_utf8(buf, nbytes, *ubuf, ulen) > 1) {
DPRINTF(("utf8 %" SIZE_T_FORMAT "u\n", *ulen));
- *code = "UTF-8 Unicode (with BOM)";
*code = "UTF-8 Unicode";
*code_mime = "utf-8";
} else if ((ucs_type = looks_ucs16(buf, nbytes, *ubuf, ulen)) != 0) {