changeset 1024:bcb849782534

template: use size_t in lexer input function Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 18 Jul 2020 10:44:17 -0400
parents a39617d07de4
children 3f5fdd9f1be5
files template.l
diffstat 1 files changed, 5 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/template.l	Sat Jul 18 10:50:39 2020 -0400
+++ b/template.l	Sat Jul 18 10:44:17 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2012-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -36,7 +36,7 @@
 
 #define YY_INPUT(buf, result, max_size)	\
 	result = tmpl_input_proc(buf, max_size, yyscanner)
-int tmpl_input_proc(char *buf, int size, yyscan_t scanner);
+static size_t tmpl_input_proc(char *buf, size_t size, yyscan_t scanner);
 
 static void inc_lineno(yyscan_t scanner);
 %}
@@ -62,10 +62,10 @@
 	out->lineno++;
 }
 
-int tmpl_input_proc(char *buf, int size, yyscan_t scanner)
+static size_t tmpl_input_proc(char *buf, size_t size, yyscan_t scanner)
 {
 	struct parser_output *out;
-	int num;
+	ssize_t num;
 
 	out = (struct parser_output *) tmpl_get_extra(scanner);
 	num = out->len - out->pos;
@@ -73,8 +73,7 @@
 	if (num <= 0)
 		return 0;
 
-	if (num > size)
-		num = size;
+	num = MIN(num, size);
 
 	memcpy(buf, out->input + out->pos, num);
 	out->pos += num;