From: Takao Abe Date: Sun, 7 May 2017 02:38:45 +0000 (+0000) Subject: refclock_jjy.c, ChangeLog: X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2c58a03fbf5d97fb81f6cf5446025b9b83c6dd9;p=thirdparty%2Fntp.git refclock_jjy.c, ChangeLog: [Bug 3408] refclock_jjy.c : Avoid a wrong report of the coverity static analysis tool. bk: 590e88b5qziS1ELXnoGVinu7IwFnpA --- diff --git a/ChangeLog b/ChangeLog index a1a1cfae4..b8fe26c4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +* [Bug 3408] refclock_jjy.c : Avoid a wrong report of the coverity static + analysis tool. + --- (4.2.8p10-win-beta1) 2017/03/21 Released by Harlan Stenn (4.2.8p10) diff --git a/ntpd/refclock_jjy.c b/ntpd/refclock_jjy.c index 22636a0af..2429ee489 100644 --- a/ntpd/refclock_jjy.c +++ b/ntpd/refclock_jjy.c @@ -110,6 +110,11 @@ /* [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 ;