Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at pcapng.c:928

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

pcapng_read_interface_statistics_block

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/pcapng.c)expand/collapse
Show more  
 891  pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock,int *err, gchar **err_info _U_)
 892  {
 893          int bytes_read;
 894          int block_read;
 895          int to_read;
 896          pcapng_interface_statistics_block_t isb;
 897          pcapng_option_header_t oh;
 898          char option_content[100]; /* XXX - size might need to be increased, if we see longer options */
 899   
 900   
 901          /* "Interface Statistics Block" read fixed part */
 902          errno = WTAP_ERR_CANT_READ;
 903          bytes_read = file_read(&isb, 1, sizeof isb, fh);
 904          if (bytes_read != sizeof isb) {
 905                  pcapng_debug0("pcapng_read_interface_statistics_block: failed to read packet data");
 906                  *err = file_error(fh);
 907                  return 0;
 908          }
 909          block_read = bytes_read;
 910   
 911          if(pn->byte_swapped) {
 912                  wblock->data.if_stats.interface_id      = BSWAP64(isb.interface_id);
 913                  wblock->data.if_stats.ts_high           = BSWAP32(isb.timestamp_high);
 914                  wblock->data.if_stats.ts_low            = BSWAP32(isb.timestamp_low);
 915          } else {
 916                  wblock->data.if_stats.interface_id      = isb.interface_id;
 917                  wblock->data.if_stats.ts_high           = isb.timestamp_high;
 918                  wblock->data.if_stats.ts_low            = isb.timestamp_low;
 919          }
 920          pcapng_debug1("pcapng_read_interface_statistics_block: interface_id %" G_GINT64_MODIFIER "u", wblock->data.if_stats.interface_id);
 921   
 922          /* Option defaults */
 923          wblock->data.if_stats.opt_comment = NULL;
 924          wblock->data.if_stats.isb_ifrecv  = -1;
 925          wblock->data.if_stats.isb_ifdrop  = -1;
 926   
 927          /* Options */
 928          errno = WTAP_ERR_CANT_READ;
 929          to_read = bh->block_total_length  
 930          - sizeof(pcapng_block_header_t)  
 931          - block_read    /* fixed and variable part, including padding */
 932          - sizeof(bh->block_total_length);
 933          while(to_read > 0) {
 934                  /* read option */
 935                  bytes_read = pcapng_read_option(fh, pn, &oh, option_content, sizeof(option_content), err, err_info);
 936                  if (bytes_read <= 0) {
 937                          pcapng_debug0("pcapng_read_interface_statistics_block: failed to read option");
 938                          return bytes_read;
 939                  }
 940                  block_read += bytes_read;
 941                  to_read -= bytes_read;
 942   
 943                  /* handle option content */
 944                  switch(oh.option_code) {
 945                      case(0): /* opt_endofopt */
 946                          if(to_read != 0) {
 947                                  pcapng_debug1("pcapng_read_interface_statistics_block: %u bytes after opt_endofopt", to_read);
 948                          }
 949                          /* padding should be ok here, just get out of this */
 950                          to_read = 0;
 951                          break;
 952                      case(1): /* opt_comment */
 953                          if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) {
 954                                  wblock->data.section.opt_comment = g_strndup(option_content, sizeof(option_content));
 955                                  pcapng_debug1("pcapng_read_interface_statistics_block: opt_comment %s", wblock->data.section.opt_comment);
 956                          } else {
 957                                  pcapng_debug1("pcapng_read_interface_statistics_block: opt_comment length %u seems strange", oh.option_length);
 958                          }
 959                          break;
 960                      case(4): /* isb_ifrecv */
 961                          if(oh.option_length == 8) {
 962                                  /*  Don't cast a char[] into a guint32--the
 963                                   *  char[] may not be aligned correctly.
 964                                   */
 965                                  memcpy(&wblock->data.if_stats.isb_ifrecv, option_content, sizeof(guint64));
 966                                  if(pn->byte_swapped)  
 967                                          wblock->data.if_stats.isb_ifrecv = BSWAP64(wblock->data.if_stats.isb_ifrecv);
 968                                  pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifrecv %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_ifrecv);
 969                          } else {
 970                                  pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifrecv length %u not 8 as expected", oh.option_length);
 971                          }
 972                          break;
 973                      case(5): /* isb_ifdrop */
 974                          if(oh.option_length == 8) {
 975                                  /*  Don't cast a char[] into a guint32--the
 976                                   *  char[] may not be aligned correctly.
 977                                   */
 978                                  memcpy(&wblock->data.if_stats.isb_ifdrop, option_content, sizeof(guint64));
 979                                  if(pn->byte_swapped)  
 980                                          wblock->data.if_stats.isb_ifdrop = BSWAP64(wblock->data.if_stats.isb_ifdrop);
 981                                  pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifdrop %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_ifdrop);
 982                          } else {
 983                                  pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifdrop length %u not 8 as expected", oh.option_length);
 984                          }
 985                          break;
 986                      default:
 987                          pcapng_debug2("pcapng_read_interface_statistics_block: unknown option %u - ignoring %u bytes",
 988                                        oh.option_code, oh.option_length);
 989                  }
 990          }
 991   
 992      return block_read;
 993  }
Show more  




Change Warning 1045.29958 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: