Text   |  XML   |  ReML   |   Visible Warnings:

Unreachable Control Flow  at packet-h264.c:624

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

dissect_h264_exp_golomb_code

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-h264.c)expand/collapse
Show more  
 377  dissect_h264_exp_golomb_code(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint *start_bit_offset, h264_golomb_descriptors descriptor)
 378  /*(tvbuff_t *tvb, gint *start_bit_offset) */
 379  {
 380          gint            leading_zero_bits, bit_offset;
 381          guint32         codenum, mask, value, tmp;
 382          gint32          se_value=0;              
 383          gint            b;
 384          char *str;
 385          int bit;
 386          int i;
 387          header_field_info *hf_field = NULL;
 388   
 389          if(hf_index > -1)
 390                  hf_field = proto_registrar_get_nth(hf_index);
 391   
 392          bit_offset = *start_bit_offset;
 393   
 394          /* prepare the string */
 395          str=ep_alloc(256);
 396          str[0]='\0';
 397          for(bit=0;bit<((int)(bit_offset&0x07));bit++){
 398                  if(bit&&(!(bit%4))){
 399                          g_strlcat(str, " ", 256);
 400                  }
 401                  g_strlcat(str,".", 256);
 402          }
 403   
 404   
 405          leading_zero_bits = -1;
 406          for( b = 0; !b; leading_zero_bits++ ){
 407                  if(bit&&(!(bit%4))){
 408                          g_strlcat(str, " ", 256);
 409                  }
 410                  if(bit&&(!(bit%8))){
 411                          g_strlcat(str, " ", 256);
 412                  }
 413                  b = tvb_get_bits8(tvb, bit_offset, 1);
 414                  if(b != 0){
 415                          g_strlcat(str, "1", 256);
 416                  } else {
 417                          g_strlcat(str, "0", 256);
 418                  }
 419                  bit++;
 420                  bit_offset++;
 421          }
 422   
 423          if(leading_zero_bits==0){
 424                  codenum = 0;
 425                  *start_bit_offset = bit_offset;
 426                  for(;bit%8;bit++){
 427                          if(bit&&(!(bit%4))){
 428                                  g_strlcat(str, " ", 256);
 429                          }
 430                  g_strlcat(str,".", 256);
 431                  }
 432                  if(hf_field){
 433                          g_strlcat(str," = ", 256);
 434                          g_strlcat(str,hf_field->name, 256);
 435                          switch (descriptor){
 436                          case H264_SE_V:
 437                                  /* if the syntax element is coded as se(v),  
 438                                   * the value of the syntax element is derived by invoking the 
 439                                   * mapping process for signed Exp-Golomb codes as specified in  
 440                                   * subclause 9.1.1 with codeNum as the input.
 441                                   */
 442                                  if(hf_field->type==FT_INT32){
 443                                          if (hf_field->strings) {
 444                                                  proto_tree_add_int_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
 445                                                            "%s: %s (%d)",
 446                                                            str,
 447                                                            val_to_str(codenum, cVALS(hf_field->strings), "Unknown "),
 448                                                            codenum);
 449                                          }else{
 450                                                  switch(hf_field->display){
 451                                                          case BASE_DEC:
 452                                                                  proto_tree_add_int_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
 453                                                                   "%s: %d",
 454                                                                            str,
 455                                                                            codenum);
 456                                                                  break;
 457                                                          default:
 458                                                                  DISSECTOR_ASSERT_NOT_REACHED();
 459                                                                  break;
 460                                                  }
 461                                          }
 462                                  }
 463                                  return codenum;
 464                          default:
 465                                  break;
 466                          }
 467                          if(hf_field->type==FT_UINT32){
 468                                  if (hf_field->strings) {
 469                                          proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
 470                                                    "%s: %s (%u)",
 471                                                    str,
 472                                                    val_to_str(codenum, cVALS(hf_field->strings), "Unknown "),
 473                                                    codenum);
 474                                  }else{
 475                                          switch(hf_field->display){
 476                                                  case BASE_DEC:
 477                                                          proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
 478                                                           "%s: %u",
 479                                                                    str,
 480                                                                    codenum);
 481                                                          break;
 482                                                  case BASE_HEX:
 483                                                          proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
 484                                                       "%s: 0x%x",
 485                                                                    str,
 486                                                                    codenum);
 487                                                          break;
 488                                                  default:
 489                                                          DISSECTOR_ASSERT_NOT_REACHED();
 490                                                          break;
 491                                          }
 492                                  }
 493                          }else{
 494                                  /* Only allow guint32 */
 495                                  DISSECTOR_ASSERT_NOT_REACHED();
 496                          }
 497                  }
 498                  return codenum;
 499          }
 500   
 501          /*
 502          Syntax elements coded as ue(v), me(v), or se(v) are Exp-Golomb-coded. Syntax elements coded as te(v) are truncated
 503          Exp-Golomb-coded. The parsing process for these syntax elements begins with reading the bits starting at the current
 504          location in the bitstream up to and including the first non-zero bit, and counting the number of leading bits that are 
 505          equal to 0. This process is specified as follows:
 506          leadingZeroBits = -1;
 507          for( b = 0; !b; leadingZeroBits++ )
 508          b = read_bits( 1 )
 509          The variable codeNum is then assigned as follows:
 510          codeNum = 2leadingZeroBits - 1 + read_bits( leadingZeroBits )
 511          where the value returned from read_bits( leadingZeroBits ) is interpreted as a binary representation of an unsigned 
 512          integer with most significant bit written first.
 513          */
 514          codenum = 1;
 515          codenum = codenum << leading_zero_bits;
 516          mask = codenum>>1;
 517          if (leading_zero_bits > 8)
 518                  value = tvb_get_bits16(tvb, bit_offset,leading_zero_bits, FALSE);
 519          else 
 520                  value = tvb_get_bits8(tvb, bit_offset,leading_zero_bits );
 521          codenum = (codenum-1) + value;  
 522          bit_offset = bit_offset + leading_zero_bits;
 523   
 524          /* read the bits for the int */
 525          for(i=0;i<leading_zero_bits;i++){
 526                  if(bit&&(!(bit%4))){
 527                          g_strlcat(str, " ", 256);
 528                  }
 529                  if(bit&&(!(bit%8))){
 530                          g_strlcat(str, " ", 256);
 531                  }
 532                  bit++;
 533                  tmp = value & mask;
 534                  if(tmp != 0){
 535                          g_strlcat(str, "1", 256);
 536                  } else {
 537                          g_strlcat(str, "0", 256);
 538                  }
 539                  mask = mask>>1;
 540          }
 541          for(;bit%8;bit++){
 542                  if(bit&&(!(bit%4))){
 543                          g_strlcat(str, " ", 256);
 544                  }
 545                  g_strlcat(str,".", 256);
 546          }
 547   
 548          switch (descriptor){
 549          case H264_SE_V:
 550                  /* if the syntax element is coded as se(v),  
 551                   * the value of the syntax element is derived by invoking the 
 552                   * mapping process for signed Exp-Golomb codes as specified in  
 553                   * subclause 9.1.1 with codeNum as the input.
 554                   *              k+1  
 555                   * (-1)    Ceil( k/2 )
 556                   */
 557                  se_value = (codenum + 1) >> 1;
 558                  if (!(se_value & 1)){
 559                          se_value =  - se_value;
 560                  }
 561                  break;
 562          default:
 563                  break;
 564          }
 565   
 566          if(hf_field){
 567                  g_strlcat(str," = ", 256);
 568                  g_strlcat(str,hf_field->name, 256);
 569                  switch (descriptor){
 570                  case H264_SE_V:
 571                          g_strlcat(str,"(se(v))", 256);
 572                          /* if the syntax element is coded as se(v),  
 573                           * the value of the syntax element is derived by invoking the 
 574                           * mapping process for signed Exp-Golomb codes as specified in  
 575                           * subclause 9.1.1 with codeNum as the input.
 576                           */
 577                          break;
 578                  default:
 579                  break;
 580                  }
 581                  if((hf_field->type==FT_UINT32)&&(descriptor==H264_UE_V)){
 582                          if (hf_field->strings) {
 583                                  proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
 584                                                    "%s: %s (%u)",
 585                                                    str,
 586                                                    val_to_str(codenum, cVALS(hf_field->strings), "Unknown "),
 587                                                    codenum);
 588                          }else{
 589                                  switch(hf_field->display){
 590                                          case BASE_DEC:
 591                                                  proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
 592                                                   "%s: %u",
 593                                                            str,
 594                                                            codenum);
 595                                                  break;
 596                                          case BASE_HEX:
 597                                                  proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
 598                                               "%s: 0x%x",
 599                                                            str,
 600                                                            codenum);
 601                                                  break;
 602                                          default:
 603                                                  DISSECTOR_ASSERT_NOT_REACHED();
 604                                                  break;
 605                                  }
 606                          }
 607                  }else if((hf_field->type==FT_INT32)&&(descriptor==H264_SE_V)){
 608                          if (hf_field->strings) {
 609                                  proto_tree_add_int_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
 610                                                    "%s: %s (%d)",
 611                                                    str,
 612                                                    val_to_str(codenum, cVALS(hf_field->strings), "Unknown "),
 613                                                    se_value);
 614                          }else{
 615                                  switch(hf_field->display){
 616                                          case BASE_DEC:
 617                                                  proto_tree_add_int_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
 618                                                   "%s: %d",
 619                                                            str,
 620                                                            se_value);
 621                                                  break;
 622                                          default:
 623                                                  DISSECTOR_ASSERT_NOT_REACHED();
 624                                                  break;
 625                                  }
 626                          }
 627                          *start_bit_offset = bit_offset;
 628                          return se_value;
 629   
 630                  }else{
 631                          /* Only allow guint32 */
 632                          DISSECTOR_ASSERT_NOT_REACHED();
 633                  }
 634          }
 635   
 636          *start_bit_offset = bit_offset;
 637          return codenum;
 638   
 639  }
Show more  




Change Warning 2632.31453 : Unreachable Control Flow

Because they are very similar, this warning shares annotations with warnings 2632.31454, 2632.31455, and 2632.31456.

Priority:
State:
Finding:
Owner:
Note: