linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ir-ctl: increase the size of the buffer used to read raw files
@ 2021-09-13  0:51 Norman Rasmussen
  2021-09-13  7:16 ` Sean Young
  0 siblings, 1 reply; 2+ messages in thread
From: Norman Rasmussen @ 2021-09-13  0:51 UTC (permalink / raw)
  To: Sean Young; +Cc: linux-media

Air conditioner codes typically have 100 pulse/space pairs (12 bytes +
headers). The resulting raw IR line length is 1063, which exceeds the
current 1024 byte buffer, and results in an error trying to parse the
line.

The buffers used to read pulse/space files are significantly larger than
needed so this decreases their size, and allocates the difference to the
buffer used to read raw IR files in order to keep the total size of
buffers the same.

Signed-off-by: Norman Rasmussen <norman@rasmussen.co.za>
---
  utils/ir-ctl/ir-ctl.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/utils/ir-ctl/ir-ctl.c b/utils/ir-ctl/ir-ctl.c
index 3c3bcca1..46fe12d9 100644
--- a/utils/ir-ctl/ir-ctl.c
+++ b/utils/ir-ctl/ir-ctl.c
@@ -211,7 +211,7 @@ static struct send *read_file_pulse_space(struct arguments 
*args, const char *fn
  {
  	bool expect_pulse = true;
  	int lineno = 0, lastspace = 0;
-	char line[1024];
+	char line[512];
  	int len = 0;
  	static const char whitespace[] = " \n\r\t";
  	struct send *f;
@@ -380,7 +380,7 @@ static struct send *read_file_pulse_space(struct arguments 
*args, const char *fn
  static struct send *read_file_raw(struct arguments *args, const char *fname, 
FILE *input)
  {
  	int lineno = 0, lastspace = 0;
-	char line[1024];
+	char line[2048];
  	int len = 0;
  	static const char whitespace[] = " \n\r\t,";
  	struct send *f;
@@ -474,7 +474,7 @@ static struct send *read_file_raw(struct arguments *args, 
const char *fname, FIL
  static struct send *read_file(struct arguments *args, const char *fname)
  {
  	FILE *input = fopen(fname, "r");
-	char line[1024];
+	char line[512];

  	if (!input) {
  		fprintf(stderr, _("%s: could not open: %m\n"), fname);
-- 
2.30.2


-- 
- Norman Rasmussen
  - Email: norman@rasmussen.co.za
  - Home page: http://norman.rasmussen.co.za/

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ir-ctl: increase the size of the buffer used to read raw files
  2021-09-13  0:51 [PATCH] ir-ctl: increase the size of the buffer used to read raw files Norman Rasmussen
@ 2021-09-13  7:16 ` Sean Young
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Young @ 2021-09-13  7:16 UTC (permalink / raw)
  To: Norman Rasmussen; +Cc: linux-media

On Sun, Sep 12, 2021 at 05:51:06PM -0700, Norman Rasmussen wrote:
> Air conditioner codes typically have 100 pulse/space pairs (12 bytes +
> headers). The resulting raw IR line length is 1063, which exceeds the
> current 1024 byte buffer, and results in an error trying to parse the
> line.

Right, thanks for catching that.

> The buffers used to read pulse/space files are significantly larger than
> needed so this decreases their size, and allocates the difference to the
> buffer used to read raw IR files in order to keep the total size of
> buffers the same.

Decreasing the other sizes is not necessary, and is probably a bad thing. If
anything, I would say all of them can be increased. Something like 4096.
ir-ctl uses very little stack space so increasing them won't do any harm,
but will prevent others running into problems if their lines are too long.

Thanks,

Sean

> 
> Signed-off-by: Norman Rasmussen <norman@rasmussen.co.za>
> ---
>  utils/ir-ctl/ir-ctl.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/utils/ir-ctl/ir-ctl.c b/utils/ir-ctl/ir-ctl.c
> index 3c3bcca1..46fe12d9 100644
> --- a/utils/ir-ctl/ir-ctl.c
> +++ b/utils/ir-ctl/ir-ctl.c
> @@ -211,7 +211,7 @@ static struct send *read_file_pulse_space(struct
> arguments *args, const char *fn
>  {
>  	bool expect_pulse = true;
>  	int lineno = 0, lastspace = 0;
> -	char line[1024];
> +	char line[512];
>  	int len = 0;
>  	static const char whitespace[] = " \n\r\t";
>  	struct send *f;
> @@ -380,7 +380,7 @@ static struct send *read_file_pulse_space(struct
> arguments *args, const char *fn
>  static struct send *read_file_raw(struct arguments *args, const char
> *fname, FILE *input)
>  {
>  	int lineno = 0, lastspace = 0;
> -	char line[1024];
> +	char line[2048];
>  	int len = 0;
>  	static const char whitespace[] = " \n\r\t,";
>  	struct send *f;
> @@ -474,7 +474,7 @@ static struct send *read_file_raw(struct arguments
> *args, const char *fname, FIL
>  static struct send *read_file(struct arguments *args, const char *fname)
>  {
>  	FILE *input = fopen(fname, "r");
> -	char line[1024];
> +	char line[512];
> 
>  	if (!input) {
>  		fprintf(stderr, _("%s: could not open: %m\n"), fname);
> -- 
> 2.30.2
> 
> 
> -- 
> - Norman Rasmussen
>  - Email: norman@rasmussen.co.za
>  - Home page: http://norman.rasmussen.co.za/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-13  7:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13  0:51 [PATCH] ir-ctl: increase the size of the buffer used to read raw files Norman Rasmussen
2021-09-13  7:16 ` Sean Young

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).