]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
refclock_jjy.c, ChangeLog:
authorTakao Abe <abe@ntp.org>
Sun, 7 May 2017 02:38:45 +0000 (02:38 +0000)
committerTakao Abe <abe@ntp.org>
Sun, 7 May 2017 02:38:45 +0000 (02:38 +0000)
  [Bug 3408]  refclock_jjy.c : Avoid a wrong report of the coverity static analysis tool.

bk: 590e88b5qziS1ELXnoGVinu7IwFnpA

ChangeLog
ntpd/refclock_jjy.c

index a1a1cfae45a59975bb12958d206f6c0a48e631b5..b8fe26c4a041d728a6721bc2c69a755d1954a822 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+* [Bug 3408]  refclock_jjy.c : Avoid a wrong report of the coverity static
+              analysis tool. <abe@ntp.org>
+
 ---
 (4.2.8p10-win-beta1) 2017/03/21 Released by Harlan Stenn <stenn@ntp.org>
 (4.2.8p10)
index 22636a0af8cbc7780792b36ae469043a85f07711..2429ee48965fe2b0962d1d67fbe085c18bffdadd 100644 (file)
 /*    [Fix]    C-DEX JST2000                                          */
 /*             Thanks to Mr. Kuramatsu for the report and the patch.  */
 /*                                                                   */
+/*  2017/04/30                                                       */
+/*    [Change] Avoid a wrong report of the coverity static analysis   */
+/*             tool. ( The code is harmless and has no bug. )        */
+/*             teljjy_conn_send()                                    */
+/*                                                                   */
 /**********************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -393,6 +398,7 @@ struct      refclock refclock_jjy = {
 #define        JJY_CLOCKSTATS_MARK_ATTENTION   5
 #define        JJY_CLOCKSTATS_MARK_WARNING     6
 #define        JJY_CLOCKSTATS_MARK_ERROR       7
+#define        JJY_CLOCKSTATS_MARK_BUG         8
 
 /* Local constants definition for the clockstats messages */
 
@@ -3299,6 +3305,7 @@ teljjy_conn_send ( struct peer *peer, struct refclockproc *pp, struct jjyunit *u
 
        const char *    pCmd ;
        int             i, iLen, iNextClockState ;
+       char    sLog [ 120 ] ;
 
        DEBUG_TELJJY_PRINTF( "teljjy_conn_send" ) ;
 
@@ -3327,8 +3334,8 @@ teljjy_conn_send ( struct peer *peer, struct refclockproc *pp, struct jjyunit *u
                /* Loopback character comes */
 #ifdef DEBUG
                if ( debug ) {
-                       printf( "refclock_jjy.c : teljjy_conn_send : iLoopbackCount=%d\n",
-                                up->iLoopbackCount ) ;
+                       printf( "refclock_jjy.c : teljjy_conn_send : iClockCommandSeq=%d iLoopbackCount=%d\n",
+                                up->iClockCommandSeq, up->iLoopbackCount ) ;
                }
 #endif
 
@@ -3351,8 +3358,18 @@ teljjy_conn_send ( struct peer *peer, struct refclockproc *pp, struct jjyunit *u
 
                if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK ) {
                        /* Loopback character and timestamp */
-                       gettimeofday( &(up->sendTime[up->iLoopbackCount]), NULL ) ;
-                       up->bLoopbackMode = TRUE ;
+                       if ( up->iLoopbackCount < MAX_LOOPBACK ) {
+                               gettimeofday( &(up->sendTime[up->iLoopbackCount]), NULL ) ;
+                               up->bLoopbackMode = TRUE ;
+                       } else {
+                               /* This else-block is never come. */
+                               /* This code avoid wrong report of the coverity static analysis scan tool. */
+                               snprintf( sLog, sizeof(sLog)-1, "refclock_jjy.c ; teljjy_conn_send ; iClockCommandSeq=%d iLoopbackCount=%d MAX_LOOPBACK=%d",
+                                         up->iClockCommandSeq, up->iLoopbackCount, MAX_LOOPBACK ) ;
+                               jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_BUG, sLog ) ;
+                               msyslog ( LOG_ERR, sLog ) ;
+                               up->bLoopbackMode = FALSE ;
+                       }
                } else {
                        /* Regular command */
                        up->bLoopbackMode = FALSE ;
@@ -4383,6 +4400,9 @@ jjy_write_clockstats ( struct peer *peer, int iMark, const char *pData )
        case JJY_CLOCKSTATS_MARK_ERROR :
                pMark = "-X- " ;
                break ;
+       case JJY_CLOCKSTATS_MARK_BUG :
+               pMark = "!!! " ;
+               break ;
        default :
                pMark = "" ;
                break ;