$NetBSD$

--- clients/uil/UilDiags.c.orig	2012-10-22 14:50:39.000000000 +0000
+++ clients/uil/UilDiags.c
@@ -304,13 +304,13 @@ void	diag_issue_diagnostic
 	    */
 
 #ifndef NO_MESSAGE_CATALOG
-	    sprintf( loc_buffer,
+	    snprintf( loc_buffer, sizeof(loc_buffer),
 		     catgets(uil_catd, UIL_SET_MISC,
 			     UIL_MISC_0, "\t\t line: %d  file: %s"),
 		     az_src_rec->w_line_number,
 		     src_get_file_name( az_src_rec ) );
 #else
-	    sprintf( loc_buffer,
+	    snprintf( loc_buffer, sizeof(loc_buffer),
 		     "\t\t line: %d  file: %s",
 		     az_src_rec->w_line_number,
 		     src_get_file_name( az_src_rec ) );
@@ -358,7 +358,7 @@ void	diag_issue_diagnostic
 
 	    if (l_start_column != diag_k_no_column)
 #ifndef NO_MESSAGE_CATALOG
-	      sprintf(loc_buffer,
+	      snprintf(loc_buffer, sizeof(loc_buffer),
 		      catgets(uil_catd, UIL_SET_MISC,
 			      UIL_MISC_1, 
 			      "\t\t line: %d  position: %d  file: %s"),
@@ -366,7 +366,7 @@ void	diag_issue_diagnostic
 		      l_start_column + 1,
Beispiel #2
0
void	diag_issue_diagnostic
( int d_message_number, src_source_record_type *az_src_rec,
  int l_start_column, ...)

{
    va_list	ap;			/* ptr to variable length parameter */
    int		severity;		/* severity of message */
    int		message_number;		/* message number */
    char	msg_buffer[132];	/* buffer to construct message */
    char	ptr_buffer[buf_size];	/* buffer to construct pointer */
    char	loc_buffer[132];	/* buffer to construct location */
    char	src_buffer[buf_size];	/* buffer to hold source line */

    /*
    **	check if we are in a loop issuing errors
    */

    if (issuing_diagnostic)
    {
        _debug_output( "nested diagnostics issued" );
        Uil_message_count[ uil_k_severe_status ]++;
        uil_exit( uil_k_severe_status );
    }

    issuing_diagnostic = TRUE;

    /*
    **	determine the severity of the error.  For d_submit_spr we issue
    **	the fix previous error diagnostic, if we encountered prior errors;
    **  otherwise we let it thru.
    */

    message_number = d_message_number;

    if (message_number == d_submit_spr)
        if (Uil_message_count[ uil_k_error_status ] > 0)
            message_number = d_prev_error;

    severity = diag_rz_msg_table[ message_number ].l_severity;

    /*
    **	check if messages of this severity are to be reported.
    */

    switch (severity)
    {
    case uil_k_info_status:
        if (Uil_cmd_z_command.v_report_info_msg)
            break;

        issuing_diagnostic = FALSE;
        return;

    case uil_k_warning_status:
        if (Uil_cmd_z_command.v_report_warn_msg)
            break;

        issuing_diagnostic = FALSE;
        return;

    default:
        ;
    }

    Uil_message_count[ severity ]++;
    if (severity > uil_l_compile_status)
        uil_l_compile_status = severity;

    /*
    **	Diagnostic format varies considerably
    **	   1) no source
    **		message
    **	   2) source but no column
    **		source line
    **		message
    **		location in source message
    **	   3) source and column
    **		source line
    **		column pointer
    **		message
    **		location in source message
    **	   4) source and column but no access key
    **		message
    **		location in source message
    */

    /*
    **	substitute any parameters into the error message placing the
    **	resultant string in msg_buffer
    */

    va_start(ap, l_start_column);

#ifndef NO_MESSAGE_CATALOG
    vsnprintf( msg_buffer, sizeof(msg_buffer),
               catgets(uil_catd, UIL_SET1, msg_cat_table[ message_number ],
                       diag_rz_msg_table[ message_number ].ac_text),
               ap );
#else
    vsnprintf( msg_buffer, sizeof(msg_buffer),
               diag_rz_msg_table[ message_number ].ac_text,
               ap );
#endif
    va_end(ap);

    src_buffer[ 0 ] = 0;
    loc_buffer[ 0 ] = 0;
    ptr_buffer[ 0 ] = 0;

    if (az_src_rec != diag_k_no_source)
    {
        if ( !_src_null_access_key(az_src_rec->z_access_key) )
        {
            /*
            **	create the location line line
            */

#ifndef NO_MESSAGE_CATALOG
            sprintf( loc_buffer,
                     catgets(uil_catd, UIL_SET_MISC,
                             UIL_MISC_0, "\t\t line: %d  file: %s"),
                     az_src_rec->w_line_number,
                     src_get_file_name( az_src_rec ) );
#else
            sprintf( loc_buffer,
                     "\t\t line: %d  file: %s",
                     az_src_rec->w_line_number,
                     src_get_file_name( az_src_rec ) );
#endif

            /*
            **	retrieve the source line
            */

            src_buffer[ 0 ] = '\t';
            src_retrieve_source( az_src_rec, &src_buffer[ 1 ] );

            /*
            **	filter the standard unprintable characters.
            */

            lex_filter_unprintable_chars
            ( (unsigned char *)src_buffer, strlen( src_buffer ), 0 );

            /*
            **	create the column pointer if a source position was given
            */

            if (l_start_column != diag_k_no_column)
            {
                int	i;

                for (i=0;  i < l_start_column+1;  i++)
                {
                    if (src_buffer[ i ] == '\t')
                        ptr_buffer[ i ] = '\t';
                    else
                        ptr_buffer[ i ] = ' ';
                }

                ptr_buffer[ i++ ] = '*';
                ptr_buffer[ i ]   = 0;
            }
        }
        else	/* no access key */
        {
            /*
            **	create the location line line
            */

            if (l_start_column != diag_k_no_column)
#ifndef NO_MESSAGE_CATALOG
                sprintf(loc_buffer,
                        catgets(uil_catd, UIL_SET_MISC,
                                UIL_MISC_1,
                                "\t\t line: %d  position: %d  file: %s"),
                        az_src_rec->w_line_number,
                        l_start_column + 1,
                        src_get_file_name( az_src_rec ) );
#else
                sprintf(loc_buffer,
                        "\t\t line: %d  position: %d  file: %s",
                        az_src_rec->w_line_number,
                        l_start_column + 1,
                        src_get_file_name( az_src_rec ) );
#endif
            else
#ifndef NO_MESSAGE_CATALOG
                sprintf( loc_buffer, catgets(uil_catd, UIL_SET_MISC,
                                             UIL_MISC_0,
                                             "\t\t line: %d  file: %s"),
                         az_src_rec->w_line_number,
                         src_get_file_name( az_src_rec ) );
#else
                sprintf( loc_buffer,
                         "\t\t line: %d  file: %s",
                         az_src_rec->w_line_number,
                         src_get_file_name( az_src_rec ) );
#endif
        }
    }