Skip to content
This repository was archived by the owner on Dec 31, 2025. It is now read-only.

Commit 3e28d97

Browse files
committed
Parse sample and pixel rate arguments with r64_parse()
1 parent 2ea7656 commit 3e28d97

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/hacktv.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ int main(int argc, char *argv[])
509509
char *pre, *sub;
510510
int l;
511511
int r;
512+
r64_t rn;
512513

513514
/* Disable console output buffer in Windows */
514515
#ifdef WIN32
@@ -633,11 +634,29 @@ int main(int argc, char *argv[])
633634
break;
634635

635636
case 's': /* -s, --samplerate <value> */
636-
s.samplerate = atoi(optarg);
637+
638+
rn = r64_parse(optarg, NULL);
639+
if(rn.den == 0)
640+
{
641+
fprintf(stderr, "Invalid sample rate\n");
642+
return(-1);
643+
}
644+
645+
s.samplerate = (rn.num + rn.den / 2) / rn.den;
646+
637647
break;
638648

639649
case _OPT_PIXELRATE: /* --pixelrate <value> */
640-
s.pixelrate = atoi(optarg);
650+
651+
rn = r64_parse(optarg, NULL);
652+
if(rn.den == 0)
653+
{
654+
fprintf(stderr, "Invalid pixel rate\n");
655+
return(-1);
656+
}
657+
658+
s.pixelrate = (rn.num + rn.den / 2) / rn.den;
659+
641660
break;
642661

643662
case 'l': /* -l, --level <value> */

0 commit comments

Comments
 (0)