* Re: Fwd: [9front] ape scanf: add missing conversion flags
[not found] <927F9337D980CBC43F6247C4B8744B15@gmail.com>
@ 2020-05-12 16:15 ` ori
0 siblings, 0 replies; only message in thread
From: ori @ 2020-05-12 16:15 UTC (permalink / raw)
To: telephil9, 9front
> Hi Ori,
>
> Sorry for the previous forward, wrong nedmail command :)
>
> Anyway, I am not sure you saw my reply on IRC so here we go:
> - strtoimax return type should be intmax_t not long long as per the standard
> - scanf patch looks good although there is a possibility to use invalid specifiers like %llf or %hh[. The bug is already present in the current implementation though so I don't think we should consider this as a deal-breaker.
>
> Regards,
> Philippe
Thanks for the review. Yeah -- strtoimax was also in the wrong
header. Fixed.
And, I agree: separate change for stricter specifier parsing.
Here's the updated patch.
diff -r 965e0f59464d sys/include/ape/inttypes.h
--- a/sys/include/ape/inttypes.h Sun May 10 22:51:40 2020 +0200
+++ b/sys/include/ape/inttypes.h Tue May 12 09:14:05 2020 -0700
@@ -27,4 +27,6 @@
#define PRIu32 "u"
#define PRIu64 "llu"
+extern intmax_t strtoimax(const char *, char **, int);
+
#endif
diff -r 965e0f59464d sys/src/ape/lib/ap/gen/strtoll.c
--- a/sys/src/ape/lib/ap/gen/strtoll.c Sun May 10 22:51:40 2020 +0200
+++ b/sys/src/ape/lib/ap/gen/strtoll.c Tue May 12 09:14:05 2020 -0700
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <stdint.h>
#include <limits.h>
#include <errno.h>
@@ -101,3 +102,9 @@
return -n;
return n;
}
+
+intmax_t
+strtoimax(char *nptr, char **endptr, int base)
+{
+ return strtoll(nptr, endptr, base);
+}
diff -r 965e0f59464d sys/src/ape/lib/ap/stdio/vfscanf.c
--- a/sys/src/ape/lib/ap/stdio/vfscanf.c Sun May 10 22:51:40 2020 +0200
+++ b/sys/src/ape/lib/ap/stdio/vfscanf.c Tue May 12 09:14:05 2020 -0700
@@ -96,7 +96,16 @@
}
else
width=-1;
- type=*fmtp=='h' || *fmtp=='l' || *fmtp=='L'?*fmtp++:'n';
+ type = 'n';
+ if(*fmtp=='h' || *fmtp=='l' || *fmtp=='L' || *fmtp=='j' || *fmtp=='z' || *fmtp=='t')
+ type = *fmtp++;
+ if(type == 'l' && *fmtp == 'l'){
+ type = 'V';
+ fmtp++;
+ }else if(type == 'h' && *fmtp == 'h'){
+ type = 'H';
+ fmtp++;
+ }
if(!icvt[*fmtp]) goto NonSpecial;
if(!(*icvt[*fmtp])(f, &args, store, width, type))
return ncvt?ncvt:EOF;
@@ -137,7 +146,7 @@
static int
icvt_fixed(FILE *f, va_list *args,
int store, int width, int type, int unsgned, int base){
- unsigned long int num=0;
+ unsigned long long num=0;
int sign=1, ndig=0, dig;
int c;
do
@@ -194,18 +203,28 @@
switch(unsgned){
case SIGNED:
switch(type){
- case 'h': *va_arg(*args, short *)=num*sign; break;
- case 'n': *va_arg(*args, int *)=num*sign; break;
+ case 'H': *va_arg(*args, char *)=num*sign; break;
+ case 'h': *va_arg(*args, short *)=num*sign; break;
+ case 'n': *va_arg(*args, int *)=num*sign; break;
case 'l':
- case 'L': *va_arg(*args, long *)=num*sign; break;
+ case 'L': *va_arg(*args, long *)=num*sign; break;
+ case 'j':
+ case 'V': *va_arg(*args, long long*)=num*sign; break;
+ case 'z': *va_arg(*args, ssize_t*)=num*sign; break;
+ case 't': *va_arg(*args, ptrdiff_t*)=num*sign; break;
}
break;
case UNSIGNED:
switch(type){
+ case 'H': *va_arg(*args, unsigned char *)=num*sign; break;
case 'h': *va_arg(*args, unsigned short *)=num*sign; break;
case 'n': *va_arg(*args, unsigned int *)=num*sign; break;
case 'l':
case 'L': *va_arg(*args, unsigned long *)=num*sign; break;
+ case 'j':
+ case 'V': *va_arg(*args, unsigned long long *)=num*sign; break;
+ case 'z': *va_arg(*args, size_t*)=num*sign; break;
+ case 't': *va_arg(*args, ptrdiff_t*)=num*sign; break;
}
break;
case POINTER:
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-05-12 16:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <927F9337D980CBC43F6247C4B8744B15@gmail.com>
2020-05-12 16:15 ` Fwd: [9front] ape scanf: add missing conversion flags ori
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).