56 lines
1.6 KiB
Diff
56 lines
1.6 KiB
Diff
From 7e59d34206d7c962e093d4239e5367a2cd8b7623 Mon Sep 17 00:00:00 2001
|
|
From: Christos Zoulas <christos@zoulas.com>
|
|
Date: Mon, 4 Jul 2022 20:16:29 +0000
|
|
Subject: [PATCH] Handle invalid characters as octal (idea from PR/363 by
|
|
dimich)
|
|
|
|
---
|
|
src/file.c | 16 +++++++++++-----
|
|
1 file changed, 11 insertions(+), 5 deletions(-)
|
|
|
|
diff --git src/file.c src/file.c
|
|
index 5e89137d..af9be0f0 100644
|
|
--- src/file.c
|
|
+++ src/file.c
|
|
|@@ -32,7 +32,7 @@
|
|
| #include "file.h"
|
|
|
|
|
| #ifndef lint
|
|
|-FILE_RCSID("@(#)$File: file.c,v 1.197 2022/07/04 19:44:35 christos Exp $")
|
|
|+FILE_RCSID("@(#)$File: file.c,v 1.198 2022/07/04 20:16:29 christos Exp $")
|
|
| #endif /* lint */
|
|
|
|
|
| #include "magic.h"
|
|
@@ -580,8 +580,11 @@ fname_print(const char *inname)
|
|
bytesconsumed = mbrtowc(&nextchar, inname, n, &state);
|
|
if (bytesconsumed == CAST(size_t, -1) ||
|
|
bytesconsumed == CAST(size_t, -2)) {
|
|
- nextchar = *inname;
|
|
- bytesconsumed = 1;
|
|
+ nextchar = *inname++;
|
|
+ n--;
|
|
+ (void)mbrlen(NULL, 0, &state);
|
|
+ file_octal(CAST(unsigned char, nextchar));
|
|
+ continue;
|
|
}
|
|
inname += bytesconsumed;
|
|
n -= bytesconsumed;
|
|
@@ -660,9 +663,12 @@ file_mbswidth(struct magic_set *ms, const char *s)
|
|
bytesconsumed == CAST(size_t, -2)) {
|
|
nextchar = *s;
|
|
bytesconsumed = 1;
|
|
+ (void)mbrlen(NULL, 0, &state);
|
|
+ width += 4;
|
|
+ } else {
|
|
+ width += ((ms->flags & MAGIC_RAW) != 0
|
|
+ || iswprint(nextchar)) ? wcwidth(nextchar) : 4;
|
|
}
|
|
- width += ((ms->flags & MAGIC_RAW) != 0
|
|
- || iswprint(nextchar)) ? wcwidth(nextchar) : 4;
|
|
|
|
s += bytesconsumed, n -= bytesconsumed;
|
|
}
|
|
--
|
|
2.35.3
|
|
|