Changeset 1780 for trunk/dll/newview.c


Ignore:
Timestamp:
Jun 28, 2014, 8:05:22 PM (11 years ago)
Author:
Gregg Young
Message:

Fixed errors found by cppcheck. Most had the potential to cause difficult to reproduce traps. Also fixed retry code for failure to create an archive work directory and the failure of the mailto code to drop trailing >.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/newview.c

    r1673 r1780  
    198198//to the first word that contains the character then prepends <mailto: and appends >
    199199
    200 CHAR *mailstr(CHAR *pszSrc, CHAR *pszFindChar, LONG StrLens)
     200PSZ mailstr(CHAR *pszSrc, CHAR *pszFindChar, LONG StrLens)
    201201{
    202202  CHAR *pszCharCounter;
    203203  CHAR *pszTestStr = pszSrc;
    204   CHAR szMailTo[1024] = "mailto:";
     204  CHAR szMailTo[SEARCHSTRINGLEN] = "mailto:";
    205205  //CHAR szMailEnd[] = ">";
    206206
     
    216216      strcat(szMailTo, pszSrc);
    217217     // strcat(szMailTo, szMailEnd);
    218       pszSrc = szMailTo;
     218      strcpy(pszSrc, szMailTo);
    219219      return pszSrc;
    220220    }
     
    243243    strcat(szMailTo, pszSrc);
    244244    //strcat(szMailTo, szMailEnd);
    245     pszSrc = szMailTo;
     245    strcpy(pszSrc, szMailTo);
    246246    return pszSrc;
    247247    }
     
    262262      CHAR *p, *e, *pp;
    263263      SHORT count;
     264      CHAR szUrlString[SEARCHSTRINGLEN];
    264265
    265266      WinSetWindowPtr(hwnd, QWL_USER, mp2);
     
    301302      while (p && *p && p < e);
    302303      p = urld->line;
    303       if (mailstr(p, "@", e - p)) {
    304         pp = mailstr(p, "@", e - p);
    305         strcpy(urld->url, pp);
     304      if (strchr(p, '@')) {
     305        strcpy(szUrlString, urld->line);
     306        mailstr(szUrlString, "@", e - p);
     307        strcpy(urld->url, szUrlString);
     308        if (pp = strchr(urld->url, '>'))
     309          *pp = 0;
    306310        WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
    307311                          MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
     
    14001404        } // if got sim
    14011405      } // if got VIEWDATA
     1406      if (ad && !ad->stopflag) {
     1407        PostMsg(hwnd, UM_CONTAINER_FILLED, MPFROMLONG(firstline),
     1408                MPFROMLONG(cursored));
     1409        ad->relining = FALSE;
     1410      }
    14021411      WinDestroyMsgQueue(hmq2);
    14031412    }
     
    14091418#  endif
    14101419  DosPostEventSem(CompactSem);
    1411   if (ad && !ad->stopflag) { //Fixme can't post message withou HAB GKY 7-10-08
    1412     PostMsg(hwnd, UM_CONTAINER_FILLED, MPFROMLONG(firstline),
    1413             MPFROMLONG(cursored));
    1414     ad->relining = FALSE;
    1415   }
    14161420}
    14171421
     
    24262430        SHORT numsels, sSelect = 0, numinserted;
    24272431        ULONG linenum, size;
     2432        CHAR *s = NULL, *p;
    24282433
    24292434        if (!ad->hex && ad->lines) {
    24302435
    2431           CHAR *p, *e;
     2436          CHAR *e;
     2437          CHAR szUrlString[SEARCHSTRINGLEN];
    24322438
    24332439          width = (Rectl.xRight - Rectl.xLeft) / ad->fattrs.lAveCharWidth;
     
    24422448          width = e - p;
    24432449          if (!width)
    2444             goto NoAdd;
    2445 
     2450            goto NoAdd;
     2451
     2452          strcpy(szUrlString,ad->lines[whichline]);
    24462453          if ((ad->httpin && (*httprun || fHttpRunWPSDefault) &&
    2447                strnstr(ad->lines[whichline], "http://", width)) ||
     2454               strnstr(szUrlString, "http://", width)) ||
    24482455              (ad->ftpin && (*ftprun || fFtpRunWPSDefault) &&
    2449                strnstr(ad->lines[whichline], "ftp://", width)) ||
    2450               (ad->mailin && *mailrun && mailstr(ad->lines[whichline], "@", width))) {
     2456               strnstr(szUrlString, "ftp://", width)) ||
     2457              (ad->mailin && *mailrun && mailstr(szUrlString, "@", width))) {
    24512458
    24522459            USHORT ret;
     
    24562463            if (urld) {
    24572464              urld->size = sizeof(URLDATA);
    2458               urld->line = ad->lines[whichline];
     2465              urld->line = szUrlString;
    24592466              urld->len = width;
    24602467              ret = (USHORT) WinDlgBox(HWND_DESKTOP, hwnd, UrlDlgProc,
     
    25152522                }
    25162523                free(urld);
    2517                 goto NoAdd;
    2518               case 3:
     2524                goto NoAdd;
     2525              case 3:
    25192526                if (*urld->url){
    25202527                  runemf2(SEPARATE | WINDOWED,
     
    25322539            }
    25332540          }
    2534         }
    2535         //Move line to selection box at top of viewer
    2536         numsels = (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
    2537                                             LM_QUERYITEMCOUNT, MPVOID,
    2538                                             MPVOID);
    2539         if (numsels > 0) {
    2540           for (sSelect = 0; sSelect < numsels; sSelect++) {
    2541             linenum =
    2542               (ULONG) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
    2543                                         LM_QUERYITEMHANDLE,
    2544                                         MPFROM2SHORT(sSelect, 0), MPVOID);
    2545             if (linenum == whichline)
    2546               goto NoAdd;
    2547           }
    2548         }
    2549         {
    2550           CHAR *s = NULL, *p;
    2551 
    2552           if (!ad->hex && ad->lines) {
    2553             s = xmalloc(width + 2, pszSrcFile, __LINE__);
    2554             if (!s)
    2555               goto NoAdd;
    2556             strncpy(s, ad->lines[whichline], width + 1);
    2557             s[width + 1] = 0;
    2558             p = s;
    2559             while (*p) {
    2560               if (*p == '\r' || *p == '\n') {
    2561                 *p = 0;
    2562                 break;
    2563               }
    2564               p++;
    2565             }
    2566           }
    2567           else {
    2568 
    2569             register ULONG x;
    2570 
    2571             width = ad->textsize - (whichline * 16);
    2572             width = min(width, 16); //standard hexx line length
    2573             //use 80 as width * 5 gives inconsistent format on short lines
    2574             s = xmalloc(80, pszSrcFile, __LINE__);
    2575             if (!s)
    2576               goto NoAdd;
    2577             sprintf(s, "%08lx ", whichline * 16);
    2578             p = s + 9;
    2579             for (x = 0; x < width; x++) {
    2580               sprintf(p, " %02x", (UCHAR)ad->text[(whichline * 16) + x]);
    2581               p += 3;
    2582             }
    2583             *p = ' ';
    2584             p++;
    2585             *p = ' ';
    2586             p++;
    2587             for (x = 0; x < width; x++) {
    2588               *p = ad->text[(whichline * 16) + x];
    2589               p++;
    2590             }
    2591             *p = 0;
    2592           }
    2593           if (s) {
    2594             if (*s) {
    2595               ad->dummy = TRUE;
    2596               numinserted = (SHORT) WinSendDlgItemMsg(ad->hwndFrame,
    2597                                                       NEWVIEW_LISTBOX,
    2598                                                       LM_INSERTITEM,
    2599                                                       MPFROM2SHORT(LIT_END,
    2600                                                                    0),
    2601                                                       MPFROMP(s));
    2602               ad->dummy = FALSE;
    2603               if (numinserted >= 0)
    2604                 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
    2605                                   LM_SETITEMHANDLE,
    2606                                   MPFROM2SHORT(numinserted, 0),
    2607                                   MPFROMLONG(whichline));
    2608             }
    2609             free(s);
    2610           }
    2611         }
     2541          }
     2542          //Move line to selection box at top of viewer
     2543          numsels = (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
     2544                                              LM_QUERYITEMCOUNT, MPVOID,
     2545                                              MPVOID);
     2546          if (numsels > 0) {
     2547            for (sSelect = 0; sSelect < numsels; sSelect++) {
     2548              linenum =
     2549             (ULONG) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
     2550                                       LM_QUERYITEMHANDLE,
     2551                                       MPFROM2SHORT(sSelect, 0), MPVOID);
     2552              if (linenum == whichline)
     2553                goto NoAdd;
     2554            }
     2555          }
     2556          //{
     2557          if (!ad->hex && ad->lines) {
     2558          s = xmalloc(width + 2, pszSrcFile, __LINE__);
     2559          if (!s)
     2560            goto NoAdd;
     2561          strncpy(s, ad->lines[whichline], width + 1);
     2562          s[width + 1] = 0;
     2563          p = s;
     2564          while (*p) {
     2565            if (*p == '\r' || *p == '\n') {
     2566              *p = 0;
     2567              break;
     2568            }
     2569            p++;
     2570          }
     2571        }
     2572        else {
     2573
     2574          register ULONG x;
     2575
     2576          width = ad->textsize - (whichline * 16);
     2577          width = min(width, 16); //standard hexx line length
     2578          //use 80 as width * 5 gives inconsistent format on short lines
     2579          s = xmalloc(80, pszSrcFile, __LINE__);
     2580          if (!s)
     2581            goto NoAdd;
     2582          sprintf(s, "%08lx ", whichline * 16);
     2583          p = s + 9;
     2584          for (x = 0; x < width; x++) {
     2585            sprintf(p, " %02x", (UCHAR)ad->text[(whichline * 16) + x]);
     2586            p += 3;
     2587          }
     2588          *p = ' ';
     2589          p++;
     2590          *p = ' ';
     2591          p++;
     2592          for (x = 0; x < width; x++) {
     2593            *p = ad->text[(whichline * 16) + x];
     2594            p++;
     2595          }
     2596          *p = 0;
     2597        }
     2598        if (s) {
     2599          if (*s) {
     2600            ad->dummy = TRUE;
     2601            numinserted = (SHORT) WinSendDlgItemMsg(ad->hwndFrame,
     2602                                                    NEWVIEW_LISTBOX,
     2603                                                    LM_INSERTITEM,
     2604                                                    MPFROM2SHORT(LIT_END,
     2605                                                                 0),
     2606                                                    MPFROMP(s));
     2607            ad->dummy = FALSE;
     2608            if (numinserted >= 0)
     2609              WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
     2610                                LM_SETITEMHANDLE,
     2611                                MPFROM2SHORT(numinserted, 0),
     2612                                MPFROMLONG(whichline));
     2613          }
     2614          free(s);
     2615        }
     2616        //}
    26122617        if (!numsels)
    26132618          WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
Note: See TracChangeset for help on using the changeset viewer.