[hackers][surf][PATCH] FIFO patch: remove fifo file on close

2022-11-24 Thread Alex Phan
This patch goes on top to this fifo patch
https://surf.suckless.org/patches/fifo/

This removes fifo file on close either by Ctr+c in the browser or SIGINT
in the terminal.

Beware to patch this by hand. I did for the original fifo patch anyway.

I think this is better suited for the upstream source code? Please share
your thought.

Thanks Williams for the original patch.

Alex Phan

diff --git a/surf.c b/surf.c
index 001f776..69de8a1 100644
--- a/surf.c
+++ b/surf.c
@@ -144,12 +147,31 @@ static void setup(void);
 static void sigchld(int unused);
 static void sighup(int unused);
+static void sigint(int unused);
 static char *buildfile(const char *path);
 static char *buildpath(const char *path);
 static char *untildepath(const char *path);
@@ -335,6 +528,9 @@ setup(void)

/* clean up any zombies immediately */
sigchld(0);
+
+   signal(SIGINT, sigint);
+   
if (signal(SIGHUP, sighup) == SIG_ERR)
die("Can't install SIGHUP handler");

@@ -442,6 +639,13 @@ sighup(int unused)
reload(c, );
 }

+void
+sigint(int unused)
+{
+   cleanup();
+   die("Exiting...");
+}
+
 char *
 buildfile(const char *path)
 {
@@ -1934,6 +2304,8 @@ void
 stop(Client *c, const Arg *a)
 {
webkit_web_view_stop_loading(c->view);
+   cleanup();
die("Exiting...");
 }





[hackers] [libgrapheme] Do not falsely read entire buffer instead of simply the filled with || Laslo Hunhold

2022-11-24 Thread git
commit c10fbb9b0a7b564ba47314387cc8f5bc4f83db77
Author: Laslo Hunhold 
AuthorDate: Thu Nov 24 13:29:31 2022 +0100
Commit: Laslo Hunhold 
CommitDate: Thu Nov 24 15:51:06 2022 +0100

Do not falsely read entire buffer instead of simply the filled with

This was caught via dynamic analysis (clang asan), which I can definitely
recommend.

Rust evangelists might see this as a prime example for why C is bad, but
I still think the benefits outweigh the risks if you consider the
maturity of tooling to catch these kinds of errors. In an ideal world we
would all be programming in Ada, but C's portability is unmatched.

Signed-off-by: Laslo Hunhold 

diff --git a/test/bidirectional.c b/test/bidirectional.c
index 8646afe..f7c6081 100644
--- a/test/bidirectional.c
+++ b/test/bidirectional.c
@@ -34,7 +34,7 @@ main(int argc, char *argv[])
bidirectional_test[i].cplen,
bidirectional_test[i].mode[m], data, datalen);
grapheme_bidirectional_get_line_embedding_levels(
-   data, datalen, lev);
+   data, ret, lev);
 
if (ret != bidirectional_test[i].cplen ||
ret > datalen) {



Re: [hackers] [libgrapheme] Do not falsely read entire buffer instead of simply the filled with || Laslo Hunhold

2022-11-24 Thread Laslo Hunhold
On Thu, 24 Nov 2022 20:32:53 +0600
NRK  wrote:

Dear NRK,

> Small nitpick: ASan (and the other sanitizers) are *dynamic*
> analyzers, as they happen during runtime.
> 
> Static analysis is analyzing without executing anything. Examples of
> static analyzers would be clang-tidy or cppcheck. Newer GCC versions
> also have a `-fanalyzer` flag for statically analyzing C code, but in
> my experience it's not mature yet - but the direction looks promising.

yes, thanks, you are totally right, of course. :)

With best regards

Laslo



Re: [hackers] [libgrapheme] Do not falsely read entire buffer instead of simply the filled with || Laslo Hunhold

2022-11-24 Thread NRK
> This was caught via static analysis (clang asan), which I can definitely
> recommend.

Small nitpick: ASan (and the other sanitizers) are *dynamic* analyzers,
as they happen during runtime.

Static analysis is analyzing without executing anything. Examples of
static analyzers would be clang-tidy or cppcheck. Newer GCC versions
also have a `-fanalyzer` flag for statically analyzing C code, but in my
experience it's not mature yet - but the direction looks promising.

- NRK



[hackers] [libgrapheme] Do not falsely read entire buffer instead of simply the filled with || Laslo Hunhold

2022-11-24 Thread git
commit 4a46373ab48ea1692bbee2910295717aa416c323
Author: Laslo Hunhold 
AuthorDate: Thu Nov 24 13:29:31 2022 +0100
Commit: Laslo Hunhold 
CommitDate: Thu Nov 24 15:00:03 2022 +0100

Do not falsely read entire buffer instead of simply the filled with

This was caught via static analysis (clang asan), which I can definitely
recommend.

Rust evangelists might see this as a prime example for why C is bad, but
I still think the benefits outweigh the risks if you consider the
maturity of tooling to catch these kinds of errors. In an ideal world we
would all be programming in Ada, but C's portability is unmatched.

Signed-off-by: Laslo Hunhold 

diff --git a/test/bidirectional.c b/test/bidirectional.c
index 8646afe..f7c6081 100644
--- a/test/bidirectional.c
+++ b/test/bidirectional.c
@@ -34,7 +34,7 @@ main(int argc, char *argv[])
bidirectional_test[i].cplen,
bidirectional_test[i].mode[m], data, datalen);
grapheme_bidirectional_get_line_embedding_levels(
-   data, datalen, lev);
+   data, ret, lev);
 
if (ret != bidirectional_test[i].cplen ||
ret > datalen) {



[hackers] [libgrapheme] Apply format || Laslo Hunhold

2022-11-24 Thread git
commit 2a9ca2b1d2b83e6f59549bcc70cc687449690509
Author: Laslo Hunhold 
AuthorDate: Thu Nov 24 13:29:10 2022 +0100
Commit: Laslo Hunhold 
CommitDate: Thu Nov 24 13:29:10 2022 +0100

Apply format

Signed-off-by: Laslo Hunhold 

diff --git a/grapheme.h b/grapheme.h
index d0ec863..8974d4d 100644
--- a/grapheme.h
+++ b/grapheme.h
@@ -15,22 +15,23 @@ enum grapheme_bidirectional_override {
GRAPHEME_BIDIRECTIONAL_OVERRIDE_RTL,
 };
 
-void grapheme_bidirectional_get_line_embedding_levels(
-   const uint_least32_t *, size_t, int_least8_t *);
+void grapheme_bidirectional_get_line_embedding_levels(const uint_least32_t *,
+  size_t, int_least8_t *);
 
-size_t grapheme_bidirectional_preprocess(
-   const uint_least32_t *, size_t, enum grapheme_bidirectional_override,
-   uint_least32_t *, size_t);
-size_t grapheme_bidirectional_preprocess_utf8(
-   const char *, size_t, enum grapheme_bidirectional_override,
-   uint_least32_t *, size_t);
+size_t grapheme_bidirectional_preprocess(const uint_least32_t *, size_t,
+ enum grapheme_bidirectional_override,
+ uint_least32_t *, size_t);
+size_t
+grapheme_bidirectional_preprocess_utf8(const char *, size_t,
+   enum grapheme_bidirectional_override,
+   uint_least32_t *, size_t);
 
-size_t grapheme_bidirectional_reorder_line(
-   const uint_least32_t *, const int_least8_t *, size_t,
-   uint_least32_t *, size_t);
-size_t grapheme_bidirectional_reorder_line_utf8(
-   const char *, const int_least8_t *, size_t,
-   char *, size_t);
+size_t grapheme_bidirectional_reorder_line(const uint_least32_t *,
+   const int_least8_t *, size_t,
+   uint_least32_t *, size_t);
+size_t grapheme_bidirectional_reorder_line_utf8(const char *,
+const int_least8_t *, size_t,
+char *, size_t);
 
 size_t grapheme_decode_utf8(const char *, size_t, uint_least32_t *);
 size_t grapheme_encode_utf8(uint_least32_t, char *, size_t);
diff --git a/src/bidirectional.c b/src/bidirectional.c
index ac97b3c..b11974b 100644
--- a/src/bidirectional.c
+++ b/src/bidirectional.c
@@ -10,7 +10,7 @@
 
 enum state_type {
STATE_PROP,/* in 0..23, bidi_property */
-   STATE_PRESERVED_PROP,  /* in 0..23, preserved bidi_property for 
L1-rules */
+   STATE_PRESERVED_PROP,  /* in 0..23, preserved bidi_prop for L1-rule */
STATE_BRACKET_OFF, /* in 0..255, offset in bidi_bracket */
STATE_LEVEL,   /* in 0..MAX_DEPTH+1=126, embedding level */
STATE_PARAGRAPH_LEVEL, /* in 0..1, paragraph embedding level */
@@ -59,7 +59,7 @@ get_state(enum state_type t, uint_least32_t input)
 {
return (int_least16_t)((input & state_lut[t].filter_mask) >>
   state_lut[t].mask_shift) +
-  state_lut[t].value_offset;
+  state_lut[t].value_offset;
 }
 
 static inline void
@@ -329,8 +329,8 @@ ir_advance(struct isolate_runner *ir)
 }
 
 static size_t
-preprocess_isolating_run_sequence(uint_least32_t *buf, size_t buflen, size_t 
off,
-  uint_least8_t paragraph_level)
+preprocess_isolating_run_sequence(uint_least32_t *buf, size_t buflen,
+  size_t off, uint_least8_t paragraph_level)
 {
enum bidi_property sequence_prop, prop;
struct isolate_runner ir, tmp;
@@ -624,7 +624,7 @@ preprocess_paragraph(enum grapheme_bidirectional_override 
override,
for (bufoff = 0; bufoff < buflen; bufoff++) {
prop = (uint_least8_t)get_state(STATE_PROP, buf[bufoff]);
 
-   /* set paragraph level, which we need for line-level-processing 
*/
+   /* set paragraph level we need for line-level-processing */
set_state(STATE_PARAGRAPH_LEVEL, paragraph_level,
  &(buf[bufoff]));
 again:
@@ -905,7 +905,8 @@ again:
runsince = SIZE_MAX;
for (bufoff = 0; bufoff < buflen; bufoff++) {
level = (int_least8_t)get_state(STATE_LEVEL, buf[bufoff]);
-   prop = (uint_least8_t)get_state(STATE_PRESERVED_PROP, 
buf[bufoff]);
+   prop = (uint_least8_t)get_state(STATE_PRESERVED_PROP,
+   buf[bufoff]);
 
if (level == -1) {
/* ignored character */
@@ -980,8 +981,7 @@ get_bidi_bracket_off(uint_least32_t cp)
 }
 
 static size_t
-preprocess(HERODOTUS_READER *r,
-   enum grapheme_bidirectional_override override,
+preprocess(HERODOTUS_READER *r, enum grapheme_bidirectional_override override,
uint_least32_t *buf, size_t buflen)
 {