Text   |  XML   |  ReML   |   Visible Warnings:

Redundant Condition  at packet-acn.c:791

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

acn_add_dmp_data

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-acn.c)expand/collapse
Show more  
 733  acn_add_dmp_data(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, acn_dmp_adt_type *adt)
 734  {
 735    guint8 D, A;
 736    guint32 start_offset;
 737    guint32 data_size;
 738    guint32 data_value;
 739    guint32 data_address;
 740    guint32 x,y;
 741    gchar buffer[BUFFER_SIZE];
 742    proto_item *ti;
 743    guint32 ok_to_process = FALSE;
 744   
 745    start_offset = offset;
 746    buffer[0] = 0;
 747   
 748    /* We would like to rip through Property Address-Data pairs                 */
 749    /* but since we don't now how many there are nor how big the data size is,  */
 750    /* it not possible. So, we just show the whole thing as a block of date!    */
 751    /*                                                                          */
 752    /* There are a few exceptions however                                       */
 753    /* 1) if the address type is ACN_DMP_ADT_D_NS or ACN_DMP_ADT_D_RS and       */
 754    /*    or ACN_DMP_ADT_D_RE                                                   */
 755    /*    then number of bytes is <= count + 4. Each value is at least one byte */
 756    /*    and another address/data pair is at least 4 bytes so if the remaining */
 757    /*    bytes is less than the count plus 4 then the remaining data           */
 758    /*    must be all data                                                      */
 759    /*                                                                          */
 760    /* 2) if the address type is ACN_DMP_ADT_D_RE and the number of bytes       */
 761    /*    equals the number of bytes in remaining in the pdu then there is      */
 762    /*    a 1 to one match                                                      */
 763   
 764    D = ACN_DMP_ADT_EXTRACT_D(adt->flags);
 765    switch (D) {
 766      case ACN_DMP_ADT_D_NS:
 767      case ACN_DMP_ADT_D_RS:
 768        if (adt->data_length <= adt->count + 4) {
 769          ok_to_process = TRUE;
 770        }
 771        break;
 772      case ACN_DMP_ADT_D_RE:
 773        if (adt->data_length == adt->count) {
 774          ok_to_process = TRUE;
 775        }
 776        if (adt->data_length <= adt->count + 4) {
 777          ok_to_process = TRUE;
 778        }
 779        break;
 780    }
 781   
 782    if (!ok_to_process) {
 783      data_size = adt->data_length;
 784      ti = proto_tree_add_item(tree, hf_acn_data, tvb, offset, data_size, FALSE);
 785      offset += data_size;
 786      proto_item_set_text(ti, "Data and more Address-Data Pairs (further dissection not possible)");
 787      return offset;
 788    }
 789   
 790    A = ACN_DMP_ADT_EXTRACT_A(adt->flags);
 791    switch (D) {
 792      case ACN_DMP_ADT_D_NS: /* Non-range address, Single data item */
 793        /* calculate data size */
 794        data_size = adt->data_length;
 795        data_address = adt->address;
 796   
 797        switch (A) {
 798          case ACN_DMP_ADT_A_1: /* One octet address, (range: one octet address, increment, and count). */
 799            g_snprintf(buffer, BUFFER_SIZE, "Addr 0x%2.2X ->", data_address);
 800            break;
 801          case ACN_DMP_ADT_A_2: /* Two octet address, (range: two octet address, increment, and count). */
 802            g_snprintf(buffer, BUFFER_SIZE, "Addr 0x%4.4X ->", data_address);
 803            break;
 804          case ACN_DMP_ADT_A_4: /* Four octet address, (range: four octet address, increment, and count). */
 805            g_snprintf(buffer, BUFFER_SIZE, "Addr 0x%8.8X ->", data_address);
 806            break;
 807          default: /* and ACN_DMP_ADT_A_R, this reserved....so it has no meaning yet */
 808            offset += data_size;
 809            return offset;
 810        }
 811   
 812        switch (data_size) {
 813          case 1:
 814            data_value = tvb_get_guint8(tvb, offset);
 815            proto_tree_add_uint_format(tree, hf_acn_data8, tvb, offset, 1, data_value, "%s %2.2X", buffer, data_value);
 816            break;
 817          case 2:
 818            data_value = tvb_get_ntohs(tvb, offset);
 819            proto_tree_add_uint_format(tree, hf_acn_data16, tvb, offset, 2, data_value, "%s %4.4X", buffer, data_value);
 820            break;
 821          case 3:
 822            data_value = tvb_get_ntoh24(tvb, offset);
 823            proto_tree_add_uint_format(tree, hf_acn_data24, tvb, offset, 3, data_value, "%s %6.6X", buffer, data_value);
 824            break;
 825          case 4:
 826            data_value = tvb_get_ntohl(tvb, offset);
 827            proto_tree_add_uint_format(tree, hf_acn_data32, tvb, offset, 4, data_value, "%s %8.8X", buffer, data_value);
 828            break;
 829          default:
 830            /* build string of values */
 831            for (y=0;y<20 && y<data_size;y++) {
 832              data_value = tvb_get_guint8(tvb, offset+y);
 833              g_snprintf(buffer, BUFFER_SIZE, "%s %2.2X", buffer, data_value);
 834            }
 835            /* add the item */
 836            ti = proto_tree_add_item(tree, hf_acn_data, tvb, offset, data_size, FALSE);
 837            offset += data_size;
 838            /* change the text */
 839            proto_item_set_text(ti, "%s", buffer);
 840            break;
 841        } /* of switch (data_size) */
 842        offset += data_size;
 843        break;
 844   
 845      case ACN_DMP_ADT_D_RS: /* Range address, Single data item */
 846        /* calculate data size */
 847        data_size = adt->data_length;
 848        data_address = adt->address;
 849   
 850        for (x=0;x<adt->count;x++) {
 851          switch (A) {
 852            case ACN_DMP_ADT_A_1: /* One octet address, (range: one octet address, increment, and count). */
 853              g_snprintf(buffer, BUFFER_SIZE, "Addr 0x%2.2X ->", data_address);
 854              break;
 855            case ACN_DMP_ADT_A_2: /* Two octet address, (range: two octet address, increment, and count). */
 856              g_snprintf(buffer, BUFFER_SIZE, "Addr 0x%4.4X ->", data_address);
 857              break;
 858            case ACN_DMP_ADT_A_4: /* Four octet address, (range: four octet address, increment, and count). */
 859              g_snprintf(buffer, BUFFER_SIZE, "Addr 0x%8.8X ->", data_address);
 860              break;
 861            default: /* and ACN_DMP_ADT_A_R, this reserved....so it has no meaning yet */
 862              return offset;
 863          }
 864   
 865          switch (data_size) {
 866            case 1:
 867              data_value = tvb_get_guint8(tvb, offset);
 868              proto_tree_add_uint_format(tree, hf_acn_data8, tvb, offset, 1, data_value, "%s %2.2X", buffer, data_value);
 869              break;
 870            case 2:
 871              data_value = tvb_get_ntohs(tvb, offset);
 872              proto_tree_add_uint_format(tree, hf_acn_data8, tvb, offset, 2, data_value, "%s %4.4X", buffer, data_value);
 873              break;
 874            case 3:
 875              data_value = tvb_get_ntoh24(tvb, offset);
 876              proto_tree_add_uint_format(tree, hf_acn_data8, tvb, offset, 3, data_value, "%s %6.6X", buffer, data_value);
 877              break;
 878            case 4:
 879              data_value = tvb_get_ntohl(tvb, offset);
 880              proto_tree_add_uint_format(tree, hf_acn_data8, tvb, offset, 4, data_value, "%s %8.8X", buffer, data_value);
 881              break;
 882            default:
 883              /* build string of values */
 884              for (y=0;y<20 && y<data_size;y++) {
 885                data_value = tvb_get_guint8(tvb, offset+y);
 886                g_snprintf(buffer, BUFFER_SIZE, "%s %2.2X", buffer, data_value);
 887              }
 888              /* add the item */
 889              ti = proto_tree_add_item(tree, hf_acn_data, tvb, offset, data_size, FALSE);
 890              /* change the text */
 891              proto_item_set_text(ti, "%s", buffer);
 892              break;
 893          } /* of switch (data_size) */
 894          data_address += adt->increment;
 895        } /* of (x=0;x<adt->count;x++) */
 896        offset += data_size;
 897        break;
 898   
 899      case ACN_DMP_ADT_D_RE: /* Range address, Array of equal size data items */
 900        /* calculate data size */
 901        data_size = adt->data_length / adt->count;
 902        data_address = adt->address;
 903   
 904        for (x=0;x<adt->count;x++) {
 905          switch (A) {
 906            case ACN_DMP_ADT_A_1: /* One octet address, (range: one octet address, increment, and count). */
 907              g_snprintf(buffer, BUFFER_SIZE, "Addr 0x%2.2X ->", data_address);
 908              break;
 909            case ACN_DMP_ADT_A_2: /* Two octet address, (range: two octet address, increment, and count). */
 910              g_snprintf(buffer, BUFFER_SIZE, "Addr 0x%4.4X ->", data_address);
 911              break;
 912            case ACN_DMP_ADT_A_4: /* Four octet address, (range: four octet address, increment, and count). */
 913              g_snprintf(buffer, BUFFER_SIZE, "Addr 0x%8.8X ->", data_address);
 914              break;
 915            default: /* and ACN_DMP_ADT_A_R, this reserved....so it has no meaning yet */
 916              return offset;
 917          }
 918   
 919          switch (data_size) {
 920            case 1:
 921              data_value = tvb_get_guint8(tvb, offset);
 922              proto_tree_add_uint_format(tree, hf_acn_data8, tvb, offset, 1, data_value, "%s %2.2X", buffer, data_value);
 923              break;
 924            case 2:
 925              data_value = tvb_get_ntohs(tvb, offset);
 926              proto_tree_add_uint_format(tree, hf_acn_data8, tvb, offset, 2, data_value, "%s %4.4X", buffer, data_value);
 927              break;
 928            case 3:
 929              data_value = tvb_get_ntoh24(tvb, offset);
 930              proto_tree_add_uint_format(tree, hf_acn_data8, tvb, offset, 3, data_value, "%s %6.6X", buffer, data_value);
 931              break;
 932            case 4:
 933              data_value = tvb_get_ntohl(tvb, offset);
 934              proto_tree_add_uint_format(tree, hf_acn_data8, tvb, offset, 4, data_value, "%s %8.8X", buffer, data_value);
 935              break;
 936            default:
 937              /* build string of values */
 938              for (y=0;y<20 && y<data_size;y++) {
 939                data_value = tvb_get_guint8(tvb, offset+y);
 940                g_snprintf(buffer, BUFFER_SIZE, "%s %2.2X", buffer, data_value);
 941              }
 942              /* add the item */
 943              ti = proto_tree_add_item(tree, hf_acn_data, tvb, offset, data_size, FALSE);
 944              /* change the text */
 945              proto_item_set_text(ti, "%s", buffer);
 946              break;
 947          } /* of switch (data_size) */
 948   
 949          offset += data_size;
 950          data_address += adt->increment;
 951        } /* of (x=0;x<adt->count;x++) */
 952        break;
 953   
 954      case ACN_DMP_ADT_D_RM: /* Range address, Series of mixed size data items */
 955        data_size = adt->data_length;
 956        ti = proto_tree_add_item(tree, hf_acn_data, tvb, offset, data_size, FALSE);
 957        offset += data_size;
 958        /* change the text */
 959        proto_item_set_text(ti, "Mixed size data items");
 960        break;
 961    } /* of switch (D) */
 962   
 963    return offset;
 964  }
Show more  




Change Warning 1820.31902 : Redundant Condition

Priority:
State:
Finding:
Owner:
Note: