< prev index next >

src/os/posix/vm/os_posix.cpp

Print this page
rev 9644 : 8145096: Undefined behaviour in HotSpot
Summary: Fix some integer overflows
Reviewed-by: duke


 736   st->print("%s", buf);
 737 }
 738 
 739 // Writes one-line description of a combination of sigaction.sa_flags into a user
 740 // provided buffer. Returns that buffer.
 741 const char* os::Posix::describe_sa_flags(int flags, char* buffer, size_t size) {
 742   char* p = buffer;
 743   size_t remaining = size;
 744   bool first = true;
 745   int idx = 0;
 746 
 747   assert(buffer, "invalid argument");
 748 
 749   if (size == 0) {
 750     return buffer;
 751   }
 752 
 753   strncpy(buffer, "none", size);
 754 
 755   const struct {
 756     int i;




 757     const char* s;
 758   } flaginfo [] = {
 759     { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
 760     { SA_ONSTACK,   "SA_ONSTACK"   },
 761     { SA_RESETHAND, "SA_RESETHAND" },
 762     { SA_RESTART,   "SA_RESTART"   },
 763     { SA_SIGINFO,   "SA_SIGINFO"   },
 764     { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
 765     { SA_NODEFER,   "SA_NODEFER"   },
 766 #ifdef AIX
 767     { SA_ONSTACK,   "SA_ONSTACK"   },
 768     { SA_OLDSTYLE,  "SA_OLDSTYLE"  },
 769 #endif
 770     { 0, NULL }
 771   };
 772 
 773   for (idx = 0; flaginfo[idx].s && remaining > 1; idx++) {
 774     if (flags & flaginfo[idx].i) {
 775       if (first) {
 776         jio_snprintf(p, remaining, "%s", flaginfo[idx].s);




 736   st->print("%s", buf);
 737 }
 738 
 739 // Writes one-line description of a combination of sigaction.sa_flags into a user
 740 // provided buffer. Returns that buffer.
 741 const char* os::Posix::describe_sa_flags(int flags, char* buffer, size_t size) {
 742   char* p = buffer;
 743   size_t remaining = size;
 744   bool first = true;
 745   int idx = 0;
 746 
 747   assert(buffer, "invalid argument");
 748 
 749   if (size == 0) {
 750     return buffer;
 751   }
 752 
 753   strncpy(buffer, "none", size);
 754 
 755   const struct {
 756     // NB: i is an unsigned int here because SA_RESETHAND is on some
 757     // systems 0x80000000, which is implicitly unsigned.  Assignining
 758     // it to an int field would be an overflow in unsigned-to-signed
 759     // conversion.
 760     unsigned int i;
 761     const char* s;
 762   } flaginfo [] = {
 763     { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
 764     { SA_ONSTACK,   "SA_ONSTACK"   },
 765     { SA_RESETHAND, "SA_RESETHAND" },
 766     { SA_RESTART,   "SA_RESTART"   },
 767     { SA_SIGINFO,   "SA_SIGINFO"   },
 768     { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
 769     { SA_NODEFER,   "SA_NODEFER"   },
 770 #ifdef AIX
 771     { SA_ONSTACK,   "SA_ONSTACK"   },
 772     { SA_OLDSTYLE,  "SA_OLDSTYLE"  },
 773 #endif
 774     { 0, NULL }
 775   };
 776 
 777   for (idx = 0; flaginfo[idx].s && remaining > 1; idx++) {
 778     if (flags & flaginfo[idx].i) {
 779       if (first) {
 780         jio_snprintf(p, remaining, "%s", flaginfo[idx].s);


< prev index next >