| 2897 | } |
| 2898 | |
| 2899 | static ssize_t |
| 2900 | xo_format_string (xo_handle_t *xop, xo_buffer_t *xbp, xo_xff_flags_t flags, |
| 2901 | xo_format_t *xfp) |
| 2902 | { |
| 2903 | static char null[] = "(null)"; |
| 2904 | static char null_no_quotes[] = "null"; |
| 2905 | |
| 2906 | char *cp = NULL; |
| 2907 | wchar_t *wcp = NULL; |
| 2908 | ssize_t len; |
| 2909 | ssize_t cols = 0, rc = 0; |
| 2910 | ssize_t off = xbp->xb_curp - xbp->xb_bufp, off2; |
| 2911 | int need_enc = xo_needed_encoding(xop); |
| 2912 | |
| 2913 | if (xo_check_conversion(xop, xfp->xf_enc, need_enc)) |
| 2914 | return 0; |
| 2915 | |
| 2916 | len = xfp->xf_width[XF_WIDTH_SIZE]; |
| 2917 | |
| 2918 | if (xfp->xf_fc == 'm') { |
| 2919 | cp = strerror(xop->xo_errno); |
| 2920 | if (len < 0) |
| 2921 | len = cp ? strlen(cp) : 0; |
| 2922 | goto normal_string; |
| 2923 | |
| 2924 | } else if (xfp->xf_enc == XF_ENC_WIDE) { |
| 2925 | wcp = va_arg(xop->xo_vap, wchar_t *); |
| 2926 | if (xfp->xf_skip) |
| 2927 | return 0; |
| 2928 | |
| 2929 | /* |
| 2930 | * Dont' deref NULL; use the traditional "(null)" instead |
| 2931 | * of the more accurate "who's been a naughty boy, then?". |
| 2932 | */ |
| 2933 | if (wcp == NULL) { |
| 2934 | cp = null; |
| 2935 | len = sizeof(null) - 1; |
| 2936 | } |
| 2937 | |
| 2938 | } else { |
| 2939 | cp = va_arg(xop->xo_vap, char *); /* UTF-8 or native */ |
| 2940 | |
| 2941 | normal_string: |
| 2942 | if (xfp->xf_skip) |
| 2943 | return 0; |
| 2944 | |
| 2945 | /* Echo "Dont' deref NULL" logic */ |
| 2946 | if (cp == NULL) { |
| 2947 | if ((flags & XFF_NOQUOTE) && xo_style_is_encoding(xop)) { |
| 2948 | cp = null_no_quotes; |
| 2949 | len = sizeof(null_no_quotes) - 1; |
| 2950 | } else { |
| 2951 | cp = null; |
| 2952 | len = sizeof(null) - 1; |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | /* |
no test coverage detected