X-Git-Url: https://cgit.sxemacs.org/?a=blobdiff_plain;f=src%2Fdoprnt.c;h=8076a6b47fc515bf6b6ad560e94de346e44b75c2;hb=78dd9663a9a07a0572e1e286dfea557c6f5be826;hp=23de309c585264a4e795a5304cf0a19b53e2d80e;hpb=44455d60f0e281703fc03c79138c85fe295d878e;p=sxemacs diff --git a/src/doprnt.c b/src/doprnt.c index 23de309..8076a6b 100644 --- a/src/doprnt.c +++ b/src/doprnt.c @@ -397,6 +397,10 @@ get_doprnt_args(printf_spec_dynarr *specs, va_list vargs) printf_arg_t arg; REGISTER int i; int args_needed = get_args_needed(specs); + int spec_len = -1; + + if (specs) + spec_len = Dynarr_length(specs); xzero(arg); for (i = 1; i <= args_needed; i++) { @@ -404,14 +408,14 @@ get_doprnt_args(printf_spec_dynarr *specs, va_list vargs) char ch; printf_spec_t spec = 0; - for (j = 0; j < Dynarr_length(specs); j++) { + for (j = 0; j < spec_len; j++) { spec = Dynarr_atp(specs, j); if (spec->argnum == i) { break; } } - if (j == Dynarr_length(specs)) + if (j >= spec_len) error("No conversion spec for argument %d", i); ch = spec->converter; @@ -1328,8 +1332,8 @@ emacs_doprnt_1(Lisp_Object stream, const Bufbyte * format_nonreloc, } else { args = get_doprnt_args(specs, vargs); } - - for (i = 0; i < Dynarr_length(specs); i++) { + + for (i = 0; specs && i < Dynarr_length(specs); i++) { printf_spec_t spec = Dynarr_atp(specs, i); char ch; @@ -1354,26 +1358,30 @@ emacs_doprnt_1(Lisp_Object stream, const Bufbyte * format_nonreloc, was specified as an argument. Extract the data and forward it to the next spec, to which it will apply. */ if (ch == '*') { - printf_spec_t nextspec = Dynarr_atp(specs, i + 1); - Lisp_Object obj = largs[spec->argnum - 1]; - - if (INTP(obj)) { - if (spec->forwarding_precision) { - nextspec->precision = XINT(obj); - nextspec->minwidth = spec->minwidth; - } else { - nextspec->minwidth = XINT(obj); - if (XINT(obj) < 0) { - spec->minus_flag = 1; - nextspec->minwidth = - -nextspec->minwidth; + if(!largs) { + error("Invalid largs and '*' converter in emacs_doprnt_1"); + } else { + printf_spec_t nextspec = Dynarr_atp(specs, i + 1); + Lisp_Object obj = largs[spec->argnum - 1]; + + if (INTP(obj)) { + if (spec->forwarding_precision) { + nextspec->precision = XINT(obj); + nextspec->minwidth = spec->minwidth; + } else { + nextspec->minwidth = XINT(obj); + if (XINT(obj) < 0) { + spec->minus_flag = 1; + nextspec->minwidth = + -nextspec->minwidth; + } } + nextspec->minus_flag = spec->minus_flag; + nextspec->plus_flag = spec->plus_flag; + nextspec->space_flag = spec->space_flag; + nextspec->number_flag = spec->number_flag; + nextspec->zero_flag = spec->zero_flag; } - nextspec->minus_flag = spec->minus_flag; - nextspec->plus_flag = spec->plus_flag; - nextspec->space_flag = spec->space_flag; - nextspec->number_flag = spec->number_flag; - nextspec->zero_flag = spec->zero_flag; } continue; }