LCOV - code coverage report
Current view: top level - waltz/resolv - fd_dn_expand.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 26 0.0 %
Date: 2025-07-01 05:00:49 Functions: 0 1 0.0 %

          Line data    Source code
       1             : #include "fd_resolv.h"
       2             : 
       3             : int
       4             : fd_dn_expand( uchar const * base,
       5             :               uchar const * end,
       6             :               uchar const * src,
       7             :               char *        dest,
       8           0 :               int           space ) {
       9           0 :   uchar const * p = src;
      10           0 :   char * dbegin = dest;
      11           0 :   int len = -1;
      12           0 :   if( p==end || space <= 0 ) return -1;
      13           0 :   char * dend = dest + (space > 254 ? 254 : space);
      14             :   /* detect reference loop using an iteration counter */
      15           0 :   for( int i=0; i < end-base; i+=2 ) {
      16             :     /* loop invariants: p<end, dest<dend */
      17           0 :     if( *p & 0xc0 ) {
      18           0 :       if( p+1==end ) return -1;
      19           0 :       int j = ((p[0] & 0x3f) << 8) | p[1];
      20           0 :       if( len < 0 ) len = (int)( p+2-src );
      21           0 :       if( j >= end-base ) return -1;
      22           0 :       p = base+j;
      23           0 :     } else if( *p ) {
      24           0 :       if( dest != dbegin ) *dest++ = '.';
      25           0 :       int j = *p++;
      26           0 :       if( j >= end-p || j >= dend-dest ) return -1;
      27           0 :       while( j-- ) *dest++ = (char)( *p++ );
      28           0 :     } else {
      29           0 :       *dest = 0;
      30           0 :       if( len < 0 ) len = (int)( p+1-src );
      31           0 :       return len;
      32           0 :     }
      33           0 :   }
      34           0 :   return -1;
      35           0 : }

Generated by: LCOV version 1.14