示例#1
0
int vfwscanf_s(FILE* stream, const wchar_t* format, va_list arglist)
{
    int retval = 0;
    SEC_FILE_STREAM fStr = INIT_SEC_FILE_STREAM;

    if ((stream == NULL) ||  (format == NULL) )
    {
        SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
        return SCANF_EINVAL;
    }

    SECUREC_LOCK_FILE(stream);

    _VALIDATE_STREAM_ANSI_SETRET(stream, EINVAL, retval, EOF);
    fStr.pf = stream;
    fStr._flag = FILE_STREAM_FLAG;
    fStr.oriFilePos = UNINITIALIZED_FILE_POS;

    retval = securec_winput_s(&fStr, format,  arglist);
    SECUREC_UNLOCK_FILE(stream);
    if (retval < 0)
    {
        /*MaskCoverityID13633*/ /*coverity[RESOURCE_LEAK]*/
        SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
        /* coverity[leaked_storage] */
        return SCANF_EINVAL;
    }
    return retval;
}
示例#2
0
int vswscanf_s(const wchar_t* buffer, const wchar_t* format, va_list arglist)
{
    SEC_FILE_STREAM fStr = {0};
    int retval = -1;
    size_t count;

    /* validation section */
    if (buffer == NULL || format == NULL)
    {
        SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
        return SCANF_EINVAL;
    }
    count = wcslen(buffer);
    if (count == 0 || count > SECUREC_WCHAR_STRING_MAX_LEN )
    {
        SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
        return SCANF_EINVAL;
    }

    fStr._flag = MEM_STR_FLAG;
    fStr._base = fStr._ptr = (char*) buffer;
    fStr._cnt =  (int)count * ((int)WCHAR_SIZE);

    retval = securec_winput_s(&fStr, format, arglist);
    if (retval < 0 )
    {
        SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
        return SCANF_EINVAL;
    }
    return retval;
}