Re: [hackers] [tabbed][PATCH] Fix crashes when nclients == 0 in movetab() and focusurgent()
On Sun, May 7, 2017 at 8:28 PM, Quentin Rameauwrote: > I'd prefer to check against sel rather than nclients, as it's already > done throughout the rest of the code. > > I'll apply your patch with those changes if that's ok with you. Sounds good to me.
Re: [hackers] [tabbed][PATCH] Fix crashes when nclients == 0 in movetab() and focusurgent()
Hi Caleb, good catch and thanks for the patch! > + if (nclients == 0) > + return; > + I'd prefer to check against sel rather than nclients, as it's already done throughout the rest of the code. I'll apply your patch with those changes if that's ok with you.
[hackers] [tabbed][PATCH] Fix crashes when nclients == 0 in movetab() and focusurgent()
--- tabbed.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/tabbed.c b/tabbed.c index 6321575..23c3b47 100644 --- a/tabbed.c +++ b/tabbed.c @@ -502,6 +502,9 @@ focusurgent(const Arg *arg) { int c; + if (nclients == 0) + return; + for (c = (sel + 1) % nclients; c != sel; c = (c + 1) % nclients) { if (clients[c]->urgent) { focus(c); @@ -785,6 +788,9 @@ movetab(const Arg *arg) int c; Client *new; + if (nclients == 0) + return; + c = (sel + arg->i) % nclients; if (c < 0) c += nclients; -- 2.12.2
Re: [hackers] [sbase] libutil/cp.c leaks
Heyho On Sun, May 07, 2017 at 01:54:42PM +0200, Hiltjo Posthuma wrote: > I think there are some cases where libutil/cp.c can leak file descriptors. > It is a warning case, but the descriptors are not closed. > > I think only `mv` is affected. > > Patch below: > > > From af392d1a764d7420c7b05bb9e13d7766a5979894 Mon Sep 17 00:00:00 2001 > From: Hiltjo Posthuma> Date: Sun, 7 May 2017 13:50:26 +0200 > Subject: [PATCH] libutil: fix leaks > > --- > libutil/cp.c | 4 > 1 file changed, 4 insertions(+) Looks good to me! Cheers, Silvan > diff --git a/libutil/cp.c b/libutil/cp.c > index 9bb517a..a8db0a2 100644 > --- a/libutil/cp.c > +++ b/libutil/cp.c > @@ -79,6 +79,7 @@ cp(const char *s1, const char *s2, int depth) > if (mkdir(s2, st.st_mode) < 0 && errno != EEXIST) { > weprintf("mkdir %s:", s2); > cp_status = 1; > + closedir(dp); > return 0; > } > > @@ -122,15 +123,18 @@ cp(const char *s1, const char *s2, int depth) > if (unlink(s2) < 0 && errno != ENOENT) { > weprintf("unlink %s:", s2); > cp_status = 1; > + fclose(f1); > return 0; > } else if (!(f2 = fopen(s2, "w"))) { > weprintf("fopen %s:", s2); > cp_status = 1; > + fclose(f1); > return 0; > } > } else { > weprintf("fopen %s:", s2); > cp_status = 1; > + fclose(f1); > return 0; > } > } > -- > 2.12.2 > > > > -- > Kind regards, > Hiltjo >
[hackers] [blind] Add support for floats || Mattias Andrée
commit 4df594b3f48679f594e6f738981cb3baca8a42d9 Author: Mattias AndréeAuthorDate: Sun May 7 16:11:31 2017 +0200 Commit: Mattias Andrée CommitDate: Sun May 7 16:11:31 2017 +0200 Add support for floats Signed-off-by: Mattias Andrée diff --git a/README b/README index 1437aa6..5155331 100644 --- a/README +++ b/README @@ -24,6 +24,9 @@ UTILITIES blind-concat(1) Concatenate videos + blind-convert(1) + Change pixel format of a video + blind-crop(1) Extract subframes for all frames diff --git a/man/blind-convert.1 b/man/blind-convert.1 new file mode 100644 index 000..dd87b78 --- /dev/null +++ b/man/blind-convert.1 @@ -0,0 +1,47 @@ +.TH BLIND-CONVERT 1 blind +.SH NAME +blind-convert - Change pixel format of a video +.SH SYNOPSIS +.B blind-convert +.IR pixel-format " ..." +.SH DESCRIPTION +.B blind-convert +converts a video to use the pixel format +.I pixel-format +(all arguments are joined together with +a blank space). Available formats are: +.TP +.B xyza f +Unscaled CIE XYZ with unscaled alpha channel, in the +order, X, Y, Z, alpha. Each subpixel value is stored +as a single-precision floating-point number using the +local machines endianness. +.TP +.B xyza !f +Unscaled CIE XYZ with unscaled alpha channel, in the +order, X, Y, Z, alpha. Each subpixel value is stored +as a double-precision floating-point number using the +local machines endianness. This is the default format +in other commands. +.TP +.B xyza +Unscaled CIE XYZ with unscaled alpha channel, in the +order, X, Y, Z, alpha. Each subpixel value is stored +in the same format as in the input stream. +.TP +.B f +The same colour space as the input stream, but with +each subpixel value is stored as a single-precision +floating-point number using the local machines +endianness. +.TP +.B !f +The same colour space as the input stream, but with +each subpixel value is stored as a double-precision +floating-point number using the local machines +endianness. +.SH SEE ALSO +.BR blind (7) +.SH AUTHORS +Mattias Andrée +.RI < maand...@kth.se > diff --git a/man/blind-from-image.1 b/man/blind-from-image.1 index 9759ab8..7e6d057 100644 --- a/man/blind-from-image.1 +++ b/man/blind-from-image.1 @@ -30,7 +30,8 @@ Arbitrary Map image. .BR blind-write-head (1), .BR blind-next-frame (1), .BR blind-from-text (1), -.BR blind-repeat (1) +.BR blind-repeat (1), +.BR blind-convert (1) .SH AUTHORS Mattias Andrée .RI < maand...@kth.se > diff --git a/man/blind-from-video.1 b/man/blind-from-video.1 index 652639e..9172af2 100644 --- a/man/blind-from-video.1 +++ b/man/blind-from-video.1 @@ -3,6 +3,8 @@ blind-from-video - Converts a regular, cooked video to a blind video .SH SYNOPSIS .B blind-from-video +[-F +.IR pixel-format ] [-r .IR frame-rate ] [-w @@ -43,6 +45,11 @@ flag, you should also use it in .BR blind-to-video (1), otherwise the colours will be modified. .TP +.BR -F " "\fIpixel-format\fP +Select pixel format, see +.BR blind-convert (1) +for more information. +.TP .BR -h " "\fIheight\fP Change the height of the video to .IR height . diff --git a/man/blind-single-colour.1 b/man/blind-single-colour.1 index a10ea24..2e3d675 100644 --- a/man/blind-single-colour.1 +++ b/man/blind-single-colour.1 @@ -7,6 +7,8 @@ blind-single-colour - Generate a single-colour video .I frames | -f .RB ' inf '] +[-F +.IR pixel-format ] -w .I width -h @@ -50,6 +52,11 @@ head (works fine with most tools) but the video will be printed to stdout until there are no processes with an open read end to this process's stdout. .TP +.BR -F " "\fIpixel-format\fP +Select pixel format, see +.BR blind-convert (1) +for more information. +.TP .BR -w " "\fIwidth\fP The width of the video, in pixels. .TP diff --git a/man/blind.7 b/man/blind.7 index e878e78..cc3256b 100644 --- a/man/blind.7 +++ b/man/blind.7 @@ -34,6 +34,9 @@ Compress a video for network transmission .BR blind-concat (1) Concatenate videos .TP +.BR blind-convert (1) +Change pixel format of a video +.TP .BR blind-crop (1) Extract subframes for all frames .TP diff --git a/src/blind-arithm.c b/src/blind-arithm.c index e8c1f95..4b540a6 100644 --- a/src/blind-arithm.c +++ b/src/blind-arithm.c @@ -18,40 +18,56 @@ static int skip_z = 0; /* Because the syntax for a function returning a function pointer is disgusting. */ typedef void (*process_func)(struct stream *left, struct stream *right, size_t n); -#define LIST_OPERATORS\ - X(add, *lh += rh)\ - X(sub, *lh -= rh)\ - X(mul, *lh *= rh)\ - X(div, *lh /= rh)\ - X(exp, *lh = pow(*lh, rh))\ - X(log, *lh = log(*lh) / log(rh))\ - X(min, *lh = MIN(*lh, rh))\ - X(max, *lh = MAX(*lh, rh))\ - X(abs, *lh = fabs(*lh - rh) + rh) +#define LIST_OPERATORS(PIXFMT, TYPE, SUFFIX)\ + X(add, *lh += rh, PIXFMT, TYPE)\ + X(sub, *lh -= rh,
[hackers] [blind] Add blind-convert || Mattias Andrée
commit 878849c465604d90d236b3c8766bf75a4b6836d2 Author: Mattias AndréeAuthorDate: Sun May 7 16:48:25 2017 +0200 Commit: Mattias Andrée CommitDate: Sun May 7 17:10:45 2017 +0200 Add blind-convert Signed-off-by: Mattias Andrée diff --git a/Makefile b/Makefile index 3bdd7cd..c2444d8 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ BIN =\ blind-colour-srgb\ blind-compress\ blind-concat\ + blind-convert\ blind-crop\ blind-cut\ blind-decompress\ diff --git a/src/blind-convert.c b/src/blind-convert.c new file mode 100644 index 000..e26e304 --- /dev/null +++ b/src/blind-convert.c @@ -0,0 +1,82 @@ +/* See LICENSE file for copyright and license details. */ +#include "stream.h" +#include "util.h" + +#include + +USAGE("pixel-format ...") + +static void (*outconv)(double x, double y, double z, double a); + +#define INCONV(TYPE)\ + do {\ + TYPE *pixel, x, y, z, a;\ + size_t n;\ + do {\ + pixel = (TYPE *)stream->buf;\ + for (n = stream->ptr / stream->pixel_size; n--; pixel += 4) {\ + x = (TYPE)(pixel[0]);\ + y = (TYPE)(pixel[1]);\ + z = (TYPE)(pixel[2]);\ + a = (TYPE)(pixel[3]);\ + outconv(x, y, z, a);\ + }\ + n = stream->ptr - (stream->ptr % stream->pixel_size);\ + memmove(stream->buf, stream->buf + n, stream->ptr -= n);\ + } while (eread_stream(stream, SIZE_MAX));\ + if (stream->ptr)\ + eprintf("%s: incomplete frame\n", stream->file);\ + } while (0) + +#define OUTCONV(TYPE)\ + do {\ + TYPE pixel[4];\ + pixel[0] = (TYPE)x;\ + pixel[1] = (TYPE)y;\ + pixel[2] = (TYPE)z;\ + pixel[3] = (TYPE)a;\ + ewriteall(STDOUT_FILENO, pixel, sizeof(pixel), "");\ + } while (0) + +static void inconv_xyza (struct stream *stream) {INCONV(double);} +static void inconv_xyzaf(struct stream *stream) {INCONV(float);} + +static void outconv_xyza (double x, double y, double z, double a) {OUTCONV(double);} +static void outconv_xyzaf(double x, double y, double z, double a) {OUTCONV(float);} + +int +main(int argc, char *argv[]) +{ + struct stream stream; + const char *pixfmt; + void (*inconv)(struct stream *stream); + + UNOFLAGS(!argc); + + eopen_stream(, NULL); + + if (!strcmp(stream.pixfmt, "xyza")) + inconv = inconv_xyza; + else if (!strcmp(stream.pixfmt, "xyza f")) + inconv = inconv_xyzaf; + else + eprintf("input pixel format %s is not supported\n", stream.pixfmt); + + pixfmt = stream.pixfmt; + while (*argv) + pixfmt = get_pixel_format(*argv++, pixfmt); + + if (!strcmp(pixfmt, "xyza")) + outconv = outconv_xyza; + else if (!strcmp(pixfmt, "xyza f")) + outconv = outconv_xyzaf; + else + eprintf("output pixel format %s is not supported\n", pixfmt); + + strcpy(stream.pixfmt, pixfmt); + fprint_stream_head(stdout, ); + efflush(stdout, ""); + + inconv(); + return 0; +} diff --git a/src/blind-next-frame.c b/src/blind-next-frame.c index 14d2326..bd47f1d 100644 --- a/src/blind-next-frame.c +++ b/src/blind-next-frame.c @@ -56,9 +56,8 @@ main(int argc, char *argv[]) w = stream.width * stream.pixel_size; for (; stream.frames; stream.frames--) { for (h = stream.height; h; h--) { - for (n = w; n; n -= stream.ptr) { - stream.ptr = 0; - if (!enread_stream(2, , n)) + for (n = w; n; n -= stream.ptr, stream.ptr = 0) { + if (!stream.ptr && !enread_stream(2, , n)) goto done; anything = 1; enwriteall(2, STDOUT_FILENO, stream.buf, stream.ptr, ""); diff --git a/src/stream.c b/src/stream.c index 6ff71c0..46edfa8 100644 --- a/src/stream.c +++ b/src/stream.c @@ -106,6 +106,8 @@ set_pixel_size(struct stream *stream) { if (!strcmp(stream->pixfmt, "xyza")) stream->pixel_size = 4 * sizeof(double); + else if (!strcmp(stream->pixfmt, "xyza f")) + stream->pixel_size = 4 * sizeof(float); else return -1; return 0;
[hackers] [sbase] libutil/cp.c leaks
Hey, I think there are some cases where libutil/cp.c can leak file descriptors. It is a warning case, but the descriptors are not closed. I think only `mv` is affected. Patch below: >From af392d1a764d7420c7b05bb9e13d7766a5979894 Mon Sep 17 00:00:00 2001 From: Hiltjo PosthumaDate: Sun, 7 May 2017 13:50:26 +0200 Subject: [PATCH] libutil: fix leaks --- libutil/cp.c | 4 1 file changed, 4 insertions(+) diff --git a/libutil/cp.c b/libutil/cp.c index 9bb517a..a8db0a2 100644 --- a/libutil/cp.c +++ b/libutil/cp.c @@ -79,6 +79,7 @@ cp(const char *s1, const char *s2, int depth) if (mkdir(s2, st.st_mode) < 0 && errno != EEXIST) { weprintf("mkdir %s:", s2); cp_status = 1; + closedir(dp); return 0; } @@ -122,15 +123,18 @@ cp(const char *s1, const char *s2, int depth) if (unlink(s2) < 0 && errno != ENOENT) { weprintf("unlink %s:", s2); cp_status = 1; + fclose(f1); return 0; } else if (!(f2 = fopen(s2, "w"))) { weprintf("fopen %s:", s2); cp_status = 1; + fclose(f1); return 0; } } else { weprintf("fopen %s:", s2); cp_status = 1; + fclose(f1); return 0; } } -- 2.12.2 -- Kind regards, Hiltjo