IsGood() check elimination

Reasons: 1) It's unsafe - we cannot guarantee that address is still good
while it is used. 2) It's wrong in many modules which are usually just
compare pointer with zero.
This commit is contained in:
Nekotekina 2014-08-05 14:18:22 +04:00
parent 48514b0e93
commit 8f04ab07ed
52 changed files with 104 additions and 1450 deletions

View file

@ -26,9 +26,6 @@ int cellRtcGetCurrentTick(mem_ptr_t<CellRtcTick> pTick)
{
cellRtc->Log("cellRtcGetCurrentTick(pTick=0x%x)", pTick.GetAddr());
if (!pTick.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime unow = rDateTime::UNow();
pTick->tick = unow.GetTicks();
return CELL_OK;
@ -38,9 +35,6 @@ int cellRtcGetCurrentClock(mem_ptr_t<CellRtcDateTime> pClock, s32 iTimeZone)
{
cellRtc->Log("cellRtcGetCurrentClock(pClock=0x%x, time_zone=%d)", pClock.GetAddr(), iTimeZone);
if (!pClock.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime unow = rDateTime::UNow();
// Add time_zone as offset in minutes.
@ -62,9 +56,6 @@ int cellRtcGetCurrentClockLocalTime(mem_ptr_t<CellRtcDateTime> pClock)
{
cellRtc->Log("cellRtcGetCurrentClockLocalTime(pClock=0x%x)", pClock.GetAddr());
if (!pClock.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime unow = rDateTime::UNow();
pClock->year = unow.GetYear(rDateTime::TZ::Local);
@ -82,9 +73,6 @@ int cellRtcFormatRfc2822(u32 pszDateTime_addr, mem_ptr_t<CellRtcTick> pUtc, s32
{
cellRtc->Log("cellRtcFormatRfc2822(pszDateTime_addr=0x%x, pUtc=0x%x, time_zone=%d)", pszDateTime_addr, pUtc.GetAddr(), iTimeZone);
if (!pUtc.IsGood() || !Memory.IsGoodAddr(pszDateTime_addr))
return CELL_RTC_ERROR_INVALID_POINTER;
// Add time_zone as offset in minutes.
rTimeSpan tz = rTimeSpan(0, (long) iTimeZone, 0, 0);
@ -103,9 +91,6 @@ int cellRtcFormatRfc2822LocalTime(u32 pszDateTime_addr, mem_ptr_t<CellRtcTick> p
{
cellRtc->Log("cellRtcFormatRfc2822LocalTime(pszDateTime_addr=0x%x, pUtc=0x%x)", pszDateTime_addr, pUtc.GetAddr());
if (!pUtc.IsGood() || !Memory.IsGoodAddr(pszDateTime_addr))
return CELL_RTC_ERROR_INVALID_POINTER;
// Get date from ticks.
rDateTime date = rDateTime((time_t)pUtc->tick);
@ -120,9 +105,6 @@ int cellRtcFormatRfc3339(u32 pszDateTime_addr, mem_ptr_t<CellRtcTick> pUtc, s32
{
cellRtc->Log("cellRtcFormatRfc3339(pszDateTime_addr=0x%x, pUtc=0x%x, iTimeZone=%d)", pszDateTime_addr, pUtc.GetAddr(), iTimeZone);
if (!pUtc.IsGood() || !Memory.IsGoodAddr(pszDateTime_addr))
return CELL_RTC_ERROR_INVALID_POINTER;
// Add time_zone as offset in minutes.
rTimeSpan tz = rTimeSpan(0, (long) iTimeZone, 0, 0);
@ -141,9 +123,6 @@ int cellRtcFormatRfc3339LocalTime(u32 pszDateTime_addr, mem_ptr_t<CellRtcTick> p
{
cellRtc->Log("cellRtcFormatRfc3339LocalTime(pszDateTime_addr=0x%x, pUtc=0x%x)", pszDateTime_addr, pUtc.GetAddr());
if (!pUtc.IsGood() || !Memory.IsGoodAddr(pszDateTime_addr))
return CELL_RTC_ERROR_INVALID_POINTER;
// Get date from ticks.
rDateTime date = rDateTime((time_t) pUtc->tick);
@ -158,9 +137,6 @@ int cellRtcParseDateTime(mem_ptr_t<CellRtcTick> pUtc, u32 pszDateTime_addr)
{
cellRtc->Log("cellRtcParseDateTime(pUtc=0x%x, pszDateTime_addr=0x%x)", pUtc.GetAddr(), pszDateTime_addr);
if (!pUtc.IsGood() || !Memory.IsGoodAddr(pszDateTime_addr))
return CELL_RTC_ERROR_INVALID_POINTER;
// Get date from formatted string.
rDateTime date;
const std::string& format = Memory.ReadString(pszDateTime_addr);
@ -175,9 +151,6 @@ int cellRtcParseRfc3339(mem_ptr_t<CellRtcTick> pUtc, u32 pszDateTime_addr)
{
cellRtc->Log("cellRtcParseRfc3339(pUtc=0x%x, pszDateTime_addr=0x%x)", pUtc.GetAddr(), pszDateTime_addr);
if (!pUtc.IsGood() || !Memory.IsGoodAddr(pszDateTime_addr))
return CELL_RTC_ERROR_INVALID_POINTER;
// Get date from RFC3339 formatted string.
rDateTime date;
const std::string& format = Memory.ReadString(pszDateTime_addr);
@ -192,9 +165,6 @@ int cellRtcGetTick(mem_ptr_t<CellRtcDateTime> pTime, mem_ptr_t<CellRtcTick> pTic
{
cellRtc->Log("cellRtcGetTick(pTime=0x%x, pTick=0x%x)", pTime.GetAddr(), pTick.GetAddr());
if (!pTime.IsGood() || !pTick.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime datetime = rDateTime(pTime->day, (rDateTime::Month)pTime->month.ToLE(), pTime->year, pTime->hour, pTime->minute, pTime->second, (pTime->microsecond / 1000));
pTick->tick = datetime.GetTicks();
@ -205,9 +175,6 @@ int cellRtcSetTick(mem_ptr_t<CellRtcDateTime> pTime, mem_ptr_t<CellRtcTick> pTic
{
cellRtc->Log("cellRtcSetTick(pTime=0x%x, pTick=0x%x)", pTime.GetAddr(), pTick.GetAddr());
if (!pTime.IsGood() || !pTick.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date = rDateTime((time_t)pTick->tick);
pTime->year = date.GetYear(rDateTime::TZ::UTC);
@ -225,9 +192,6 @@ int cellRtcTickAddTicks(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pT
{
cellRtc->Log("cellRtcTickAddTicks(pTick0=0x%x, pTick1=0x%x, lAdd=%lld)", pTick0.GetAddr(), pTick1.GetAddr(), lAdd);
if (!pTick0.IsGood() || !pTick1.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
pTick0->tick = pTick1->tick + lAdd;
return CELL_OK;
}
@ -236,9 +200,6 @@ int cellRtcTickAddMicroseconds(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcT
{
cellRtc->Log("cellRtcTickAddMicroseconds(pTick0=0x%x, pTick1=0x%x, lAdd=%lld)", pTick0.GetAddr(), pTick1.GetAddr(), lAdd);
if (!pTick0.IsGood() || !pTick1.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date = rDateTime((time_t)pTick1->tick);
rTimeSpan microseconds = rTimeSpan(0, 0, 0, lAdd / 1000);
date.Add(microseconds);
@ -250,9 +211,6 @@ int cellRtcTickAddMicroseconds(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcT
int cellRtcTickAddSeconds(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pTick1, s64 lAdd)
{
cellRtc->Log("cellRtcTickAddSeconds(pTick0=0x%x, pTick1=0x%x, lAdd=%lld)", pTick0.GetAddr(), pTick1.GetAddr(), lAdd);
if (!pTick0.IsGood() || !pTick1.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date = rDateTime((time_t)pTick1->tick);
rTimeSpan seconds = rTimeSpan(0, 0, lAdd, 0);
@ -266,9 +224,6 @@ int cellRtcTickAddMinutes(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick>
{
cellRtc->Log("cellRtcTickAddMinutes(pTick0=0x%x, pTick1=0x%x, lAdd=%lld)", pTick0.GetAddr(), pTick1.GetAddr(), lAdd);
if (!pTick0.IsGood() || !pTick1.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date = rDateTime((time_t)pTick1->tick);
rTimeSpan minutes = rTimeSpan(0, lAdd, 0, 0);
date.Add(minutes);
@ -280,9 +235,6 @@ int cellRtcTickAddMinutes(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick>
int cellRtcTickAddHours(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pTick1, s32 iAdd)
{
cellRtc->Log("cellRtcTickAddHours(pTick0=0x%x, pTick1=0x%x, iAdd=%d)", pTick0.GetAddr(), pTick1.GetAddr(), iAdd);
if (!pTick0.IsGood() || !pTick1.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date = rDateTime((time_t)pTick1->tick);
rTimeSpan hours = rTimeSpan(iAdd, 0, 0, 0);
@ -295,9 +247,6 @@ int cellRtcTickAddHours(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pT
int cellRtcTickAddDays(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pTick1, s32 iAdd)
{
cellRtc->Log("cellRtcTickAddDays(pTick0=0x%x, pTick1=0x%x, iAdd=%d)", pTick0.GetAddr(), pTick1.GetAddr(), iAdd);
if (!pTick0.IsGood() || !pTick1.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date = rDateTime((time_t)pTick1->tick);
rDateSpan days = rDateSpan(0, 0, 0, iAdd);
@ -310,9 +259,6 @@ int cellRtcTickAddDays(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pTi
int cellRtcTickAddWeeks(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pTick1, s32 iAdd)
{
cellRtc->Log("cellRtcTickAddWeeks(pTick0=0x%x, pTick1=0x%x, iAdd=%d)", pTick0.GetAddr(), pTick1.GetAddr(), iAdd);
if (!pTick0.IsGood() || !pTick1.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date = rDateTime((time_t)pTick1->tick);
rDateSpan weeks = rDateSpan(0, 0, iAdd, 0);
@ -325,9 +271,6 @@ int cellRtcTickAddWeeks(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pT
int cellRtcTickAddMonths(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pTick1, s32 iAdd)
{
cellRtc->Log("cellRtcTickAddMonths(pTick0=0x%x, pTick1=0x%x, iAdd=%d)", pTick0.GetAddr(), pTick1.GetAddr(), iAdd);
if (!pTick0.IsGood() || !pTick1.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date = rDateTime((time_t)pTick1->tick);
rDateSpan months = rDateSpan(0, iAdd, 0, 0);
@ -340,9 +283,6 @@ int cellRtcTickAddMonths(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> p
int cellRtcTickAddYears(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pTick1, s32 iAdd)
{
cellRtc->Log("cellRtcTickAddYears(pTick0=0x%x, pTick1=0x%x, iAdd=%d)", pTick0.GetAddr(), pTick1.GetAddr(), iAdd);
if (!pTick0.IsGood() || !pTick1.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date = rDateTime((time_t)pTick1->tick);
rDateSpan years = rDateSpan(iAdd, 0, 0, 0);
@ -356,9 +296,6 @@ int cellRtcConvertUtcToLocalTime(mem_ptr_t<CellRtcTick> pUtc, mem_ptr_t<CellRtcT
{
cellRtc->Log("cellRtcConvertUtcToLocalTime(pUtc=0x%x, pLocalTime=0x%x)", pUtc.GetAddr(), pLocalTime.GetAddr());
if (!pUtc.IsGood() || !pLocalTime.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime time = rDateTime((time_t)pUtc->tick);
rDateTime local_time = time.FromUTC(false);
pLocalTime->tick = local_time.GetTicks();
@ -369,9 +306,6 @@ int cellRtcConvertLocalTimeToUtc(mem_ptr_t<CellRtcTick> pLocalTime, mem_ptr_t<Ce
{
cellRtc->Log("cellRtcConvertLocalTimeToUtc(pLocalTime=0x%x, pUtc=0x%x)", pLocalTime.GetAddr(), pUtc.GetAddr());
if (!pLocalTime.IsGood() || !pUtc.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime time = rDateTime((time_t)pLocalTime->tick);
rDateTime utc_time = time.ToUTC(false);
pUtc->tick = utc_time.GetTicks();
@ -382,9 +316,6 @@ int cellRtcGetDosTime(mem_ptr_t<CellRtcDateTime> pDateTime, mem32_t puiDosTime)
{
cellRtc->Log("cellRtcGetDosTime(pDateTime=0x%x, puiDosTime=0x%x)", pDateTime.GetAddr(), puiDosTime.GetAddr());
if (!pDateTime.IsGood() || !puiDosTime.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
// Convert to DOS time.
rDateTime date_time = rDateTime(pDateTime->day, (rDateTime::Month)pDateTime->month.ToLE(), pDateTime->year, pDateTime->hour, pDateTime->minute, pDateTime->second, (pDateTime->microsecond / 1000));
puiDosTime = date_time.GetAsDOS();
@ -396,9 +327,6 @@ int cellRtcGetTime_t(mem_ptr_t<CellRtcDateTime> pDateTime, mem64_t piTime)
{
cellRtc->Log("cellRtcGetTime_t(pDateTime=0x%x, piTime=0x%x)", pDateTime.GetAddr(), piTime.GetAddr());
if (!pDateTime.IsGood() || !piTime.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
// Convert to POSIX time_t.
rDateTime date_time = rDateTime(pDateTime->day, (rDateTime::Month)pDateTime->month.ToLE(), pDateTime->year, pDateTime->hour, pDateTime->minute, pDateTime->second, (pDateTime->microsecond / 1000));
piTime = convertToUNIXTime(date_time.GetSecond(rDateTime::TZ::UTC), date_time.GetMinute(rDateTime::TZ::UTC),
@ -411,9 +339,6 @@ int cellRtcGetWin32FileTime(mem_ptr_t<CellRtcDateTime> pDateTime, mem64_t pulWin
{
cellRtc->Log("cellRtcGetWin32FileTime(pDateTime=0x%x, pulWin32FileTime=0x%x)", pDateTime.GetAddr(), pulWin32FileTime.GetAddr());
if (!pDateTime.IsGood() || !pulWin32FileTime.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
// Convert to WIN32 FILETIME.
rDateTime date_time = rDateTime(pDateTime->day, (rDateTime::Month)pDateTime->month.ToLE(), pDateTime->year, pDateTime->hour, pDateTime->minute, pDateTime->second, (pDateTime->microsecond / 1000));
pulWin32FileTime = convertToWin32FILETIME(date_time.GetSecond(rDateTime::TZ::UTC), date_time.GetMinute(rDateTime::TZ::UTC),
@ -425,9 +350,6 @@ int cellRtcGetWin32FileTime(mem_ptr_t<CellRtcDateTime> pDateTime, mem64_t pulWin
int cellRtcSetDosTime(mem_ptr_t<CellRtcDateTime> pDateTime, u32 uiDosTime)
{
cellRtc->Log("cellRtcSetDosTime(pDateTime=0x%x, uiDosTime=0x%x)", pDateTime.GetAddr(), uiDosTime);
if (!pDateTime.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date_time;
rDateTime dos_time = date_time.SetFromDOS(uiDosTime);
@ -446,9 +368,6 @@ int cellRtcSetDosTime(mem_ptr_t<CellRtcDateTime> pDateTime, u32 uiDosTime)
int cellRtcSetTime_t(mem_ptr_t<CellRtcDateTime> pDateTime, u64 iTime)
{
cellRtc->Log("cellRtcSetTime_t(pDateTime=0x%x, iTime=0x%llx)", pDateTime.GetAddr(), iTime);
if (!pDateTime.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date_time = rDateTime((time_t)iTime);
@ -466,9 +385,6 @@ int cellRtcSetTime_t(mem_ptr_t<CellRtcDateTime> pDateTime, u64 iTime)
int cellRtcSetWin32FileTime(mem_ptr_t<CellRtcDateTime> pDateTime, u64 ulWin32FileTime)
{
cellRtc->Log("cellRtcSetWin32FileTime(pDateTime=0x%x, ulWin32FileTime=0x%llx)", pDateTime, ulWin32FileTime);
if (!pDateTime.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
rDateTime date_time = rDateTime((time_t)ulWin32FileTime);
@ -511,9 +427,6 @@ int cellRtcGetDayOfWeek(s32 year, s32 month, s32 day)
int cellRtcCheckValid(mem_ptr_t<CellRtcDateTime> pTime)
{
cellRtc->Log("cellRtcCheckValid(pTime=0x%x)", pTime.GetAddr());
if (!pTime.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
if ((pTime->year < 1) || (pTime->year > 9999)) return CELL_RTC_ERROR_INVALID_YEAR;
else if ((pTime->month < 1) || (pTime->month > 12)) return CELL_RTC_ERROR_INVALID_MONTH;
@ -529,9 +442,6 @@ int cellRtcCompareTick(mem_ptr_t<CellRtcTick> pTick0, mem_ptr_t<CellRtcTick> pTi
{
cellRtc->Log("cellRtcCompareTick(pTick0=0x%x, pTick1=0x%x)", pTick0.GetAddr(), pTick1.GetAddr());
if (!pTick0.IsGood() || !pTick1.IsGood())
return CELL_RTC_ERROR_INVALID_POINTER;
if (pTick0->tick < pTick1->tick) return -1;
else if (pTick0->tick > pTick1->tick) return 1;
else return CELL_OK;