void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
  const auto *If = Result.Nodes.getNodeAs<IfStmt>("if");
  SourceLocation ElseLoc = If->getElseLoc();
  DiagnosticBuilder Diag = diag(ElseLoc, "don't use else after return");
  Diag << removeToken(ElseLoc);

  // FIXME: Removing the braces isn't always safe. Do a more careful analysis.
  // FIXME: Change clang-format to correctly un-indent the code.
  if (const auto *CS = Result.Nodes.getNodeAs<CompoundStmt>("else"))
    Diag << removeToken(CS->getLBracLoc()) << removeToken(CS->getRBracLoc());
}
Example #2
0
/**
 * removeToken removes a token from the specified slot.
 *
 * @param slot       Pointer to slot structure.
 *
 * @return
 *                   <P><TABLE>
 *                   <TR><TD>Code</TD><TD>Meaning</TD></TR>
 *                   <TR>
 *                   <TD>CKR_OK                                 </TD>
 *                   <TD>Success                                </TD>
 *                   </TR>
 *                   <TR>
 *                   <TD>CKR_FUNCTION_FAILED                    </TD>
 *                   <TD>There is no token in the slot          </TD>
 *                   </TR>
 *                   </TABLE></P>
 */
int removeToken(struct p11Slot_t *slot)
{
	int i;

	if (slot->token == NULL) {
		return CKR_FUNCTION_FAILED;
	}

	if (!slot->primarySlot) {
		// Remove token from associated virtual slots
		for (i = 0; i < sizeof(slot->virtualSlots) / sizeof(slot->virtualSlots[0]); i++) {
			if (slot->virtualSlots[i]) {
				removeToken(slot->virtualSlots[i]);
			}
		}
	}

	if (slot->removedToken) {
		freeToken(slot->removedToken);
		slot->removedToken = NULL;
	}

	// A removed token and associated sessions are not immediately released from memory
	// to give running threads a change to complete token operations.
	slot->removedToken = slot->token;
	slot->token = NULL;
	slot->info.flags &= ~CKF_TOKEN_PRESENT;

	// Final close with resource deallocation is done from freeToken().
	tokenRemovedForSessionsOnSlot(&context->sessionPool, slot->id);

	return CKR_OK;
}
Example #3
0
/**
 * Removes tokens from the head of the list, according to the size of a
 * record.
 */
void Frontend::removeRecord()
{
	uint i;

	for (i = 0; (i < m_nRecordSize) && (m_pHeadToken != NULL); i++)
		removeToken();
}
Example #4
0
void DOMTokenList::removeInternal(const AtomicString& token) {
  // Check using contains first since it uses AtomicString comparisons instead
  // of character by character testing.
  if (!containsInternal(token))
    return;
  setValue(removeToken(value(), token));
}
Example #5
0
char *nextToken() {
    char *copy = malloc(bufferSize);
    strcpy(copy, buffer);
    char *next = strtok(copy, " ");
    buffer = removeToken(next, buffer);
    bufferSize--;
    free(copy);
    return next;
}
Example #6
0
void Preference::Unlink()
{
    QFile file(qgetenv("HOME")+IPANINI);
    file.remove();
    ui.accountLabel->setText("");
    ui.spaceLabel->setText(tr("用户空间总量:")+"0 GB");
    QString maxFileSizeStr =tr("允许上传最大文件:")+"0 MB";
    ui.maxFileSizeLabel->setText(maxFileSizeStr);
    QString usedSpace =tr("已经使用的空间:")+" 0";
    ui.usedSpaceLabel->setText(usedSpace);
    emit removeToken();
}
//
// State transition matrix for a reader, based on PCSC state changes
//
void Reader::update(const PCSC::ReaderState &state)
{
	// set new state
	unsigned long oldState = mState.state();
	mState = state;
	mState.name(mName.c_str());		// (fix name pointer, unchanged)
	
	try {
		if (state.state(SCARD_STATE_UNAVAILABLE)) {
			// reader is unusable (probably being removed)
			secdebug("reader", "%p (%s) unavailable (0x%lx)",
				this, name().c_str(), state.state());
			if (mToken)
				removeToken();
		} else if (state.state(SCARD_STATE_EMPTY)) {
			// reader is empty (no token present)
			secdebug("reader", "%p (%s) empty (0x%lx)",
				this, name().c_str(), state.state());
			if (mToken)
				removeToken();
		} else if (state.state(SCARD_STATE_PRESENT)) {
			// reader has a token inserted
			secdebug("reader", "%p (%s) card present (0x%lx)",
				this, name().c_str(), state.state());
			//@@@ is this hack worth it (with notifications in)??
			if (mToken && CssmData(state) != CssmData(pcscState()))
				removeToken();  // incomplete but better than nothing
			//@@@ or should we call some verify-still-the-same function of tokend?
			//@@@ (I think pcsc will return an error if the card changed?)
			if (!mToken)
				insertToken(NULL);
		} else {
			secdebug("reader", "%p (%s) unexpected state change (0x%lx to 0x%lx)",
				this, name().c_str(), oldState, state.state());
		}
	} catch (...) {
		secdebug("reader", "state update exception (ignored)");
	}
}
Example #8
0
::Ice::DispatchStatus
com::xiaonei::wap::push::token::TokenService::___removeToken(::IceInternal::Incoming& __inS, const ::Ice::Current& __current)
{
    __checkMode(::Ice::Normal, __current.mode);
    ::IceInternal::BasicStream* __is = __inS.is();
    __is->startReadEncaps();
    ::Ice::Int userId;
    ::Ice::Int pushType;
    __is->read(userId);
    __is->read(pushType);
    __is->endReadEncaps();
    removeToken(userId, pushType, __current);
    return ::Ice::DispatchOK;
}
Example #9
0
/**
 * checkForRemovedPCSCToken looks into a specific slot for a removed token.
 *
 * @param slot       Pointer to slot structure.
 *
 * @return
 *                   <P><TABLE>
 *                   <TR><TD>Code</TD><TD>Meaning</TD></TR>
 *                   <TR>
 *                   <TD>CKR_OK                                 </TD>
 *                   <TD>Success                                </TD>
 *                   </TR>
 *                   <TR>
 *                   <TD>CKR_HOST_MEMORY                        </TD>
 *                   <TD>Error getting memory (malloc)          </TD>
 *                   </TR>
 *                   <TR>
 *                   <TD>CKR_GENERAL_ERROR                      </TD>
 *                   <TD>Error opening slot directory           </TD>
 *                   </TR>
 *                   </TABLE></P>
 */
static int checkForRemovedPCSCToken(struct p11Slot_t *slot)
{
	int rc;
	LONG rv;

	FUNC_CALLED();

	if (slot->closed) {
		FUNC_RETURNS(CKR_TOKEN_NOT_PRESENT);
	}

	if (!slot->card) {
		FUNC_RETURNS(CKR_TOKEN_NOT_PRESENT);
	}

	rv = SCardStatus(slot->card, NULL, 0, 0, 0, 0, 0);

#ifdef DEBUG
	debug("SCardStatus: %s\n", pcsc_error_to_string(rv));
#endif

	if (rv == SCARD_S_SUCCESS) {
		FUNC_RETURNS(CKR_OK);
	} else if ((rv == SCARD_W_REMOVED_CARD) || (rv == SCARD_E_INVALID_HANDLE) || (rv == SCARD_E_READER_UNAVAILABLE)) {
		rc = removeToken(slot);
		if (rc != CKR_OK) {
			FUNC_RETURNS(rc);
		}

		rc = SCardDisconnect(slot->card, SCARD_UNPOWER_CARD);

#ifdef DEBUG
		debug("SCardDisconnect (%i, %s): %s\n", slot->id, slot->readername, pcsc_error_to_string(rc));
#endif

		// Check if a new token was inserted in the meantime
		rc = checkForNewPCSCToken(slot);

		if (rc == CKR_TOKEN_NOT_PRESENT) {
			FUNC_RETURNS(CKR_DEVICE_REMOVED);
		}
	} else {
		FUNC_FAILS(CKR_DEVICE_ERROR, "Error getting PC/SC card terminal status");
	}

	FUNC_RETURNS(rc);
}
Example #10
0
static int getAmountFromEvent(const InputEvent &event,
                              Item *&item0,
                              const int invType)
{
    Item *const item = getItemByInvIndex(event, invType);
    item0 = item;
    if (!item)
        return 0;

    std::string str = event.args;
    removeToken(str, " ");

    if (str.empty())
        return 0;

    int amount = 0;
    if (str[0] == '-')
    {
        if (str.size() > 1)
        {
            amount = item->getQuantity() - atoi(str.substr(1).c_str());
            if (amount <= 0 || amount > item->getQuantity())
                amount = item->getQuantity();
        }
    }
    else if (str == "/")
    {
        amount = item->getQuantity() / 2;
    }
    else if (str == "all")
    {
        amount = item->getQuantity();
    }
    else
    {
        amount = atoi(str.c_str());
    }
    return amount;
}
Example #11
0
void destroyTokenList(TokenList *t)
{
    char	*n;
    int		i;
    int		len;

    while (t->size > 0)
    {
        len = strlen(t->head->data);
        n = (char *) malloc(sizeof(char) * len + 1);
        strcpy(n, t->head->data);

        i = removeToken(t);
        if (i == 0)
            elog(DEBUG3, "token \"%s\" removed; actual token list size: %d", n, t->size);
        else
            elog(DEBUG3, "failed to remove token: \"%s\"", n);

        free(n);
    }

    free(t);
}
Example #12
0
void DOMSettableTokenList::removeInternal(const AtomicString& token)
{
    m_value = removeToken(m_value, token);
    m_tokens.remove(token);
}
Example #13
0
/**
 * Class destructor.
 */
Frontend::~Frontend()
{
	// Delete all pending tokens
	while (m_pHeadToken)
		removeToken();
}
Example #14
0
//inputs: a message to be decoded and executed
//output: -1 for an error, 0 otherwise
//purpose: Take in a raw message from middleman and execute the required functions depending on what the input command is.
int executeCmd(msg * currentMsg) {
    if(currentMsg == NULL) {
        return -1;
    }

    unsigned int nextCmd = currentMsg->cmd;
    unsigned char byteInfo;
    msg * rspnsMsg;

    switch ((command)nextCmd) {
    case CONNECT:
        //not implemented
        break;
    case DISCONNECT:
        //not implemented
        break;
    case SEND_MAP:
        //Android sends map to DE2 - needs to be recieved, stored and drawn
        printf("Entering send SEND_MAP\n");

        if(loadedTokenCnt < MAX_TOKENS) {
            receiveMap(currentMsg->buffer);
            drawMap();
        } else {
            printf("Error when Android sending map!\n");
            return -1;
        }

        break;
    case SEND_TOKEN:
        //Android sends token to DE2 - needs to be recieved, stored as a token, and drawn
        //	Then others need to be notified of new token
        printf("Entering send Token\n");

        //obtain free address in token array
        token *newTok = allocateToken();

        if(newTok) {
            newTok->ownerID = currentMsg->androidID;
            receiveTokenPixArr(currentMsg->buffer, &(newTok->bmp));

            drawBmp(&newTok->bmp, newTok->x, newTok->y);
        } else {
            printf("Error when Android sending token!\n");
            return -1;
        }

        // respond with token ID
        rspnsMsg = createSendTokenResponsesMsg(currentMsg, newTok);
        sendMessage(rspnsMsg);
        free(rspnsMsg->buffer);
        free(rspnsMsg);

        alertUsersOfTokenInfo(currentMsg, newTok->tokenID);

        break;
    case GET_DM:
        //Android attempts to get DM and new DM information is sent to all Android Users
        printf("In get_dm\n");
        //only allow DM to be taken if it is not already taken
        if (dmID == 0) {
            dmID = currentMsg->androidID;
            printf("New DM: %x\n", dmID);
        } else {
            printf("DM not available - player %x currently has it\n", dmID);
        }

        sendAllUsersDMID(dmID);

        printf("DM id %x\n", dmID);
        break;
    case RELEASE_DM:
        //Android attempts to release DM and new DM information is sent to all Androi Users
        printf("In release_dm\n");
        //only the DM can release their status
        if (dmID == currentMsg->androidID)
        {
            dmID = 0;
        }

        sendAllUsersDMID(dmID);

        printf("DM id %x\n", dmID);
        break;
    case GET_DM_ID:
        //All Android users get DM information
        printf("In test_get_dm\n");

        sendAllUsersDMID(dmID);

        printf("DM id %x\n", dmID);
        break;
    case MOVE_TOKEN:
        //Android moves token on DE2 - needs structure to be updated, and redrawn
        //	Then others need to be notified of new token position
        printf("In move_token\n");
        handleMoveTokenMsg(currentMsg);
        alertUsersOfTokenInfo(currentMsg, currentMsg->buffer[0]);
        break;

    case HANDSHAKE:
        //return identical message to Android that was recieved
        printf("In hand_shake command\n");
        sendMessage(currentMsg);
        break;

    case PASS_MSG:
        //Pass message between Android users
        printf("In Pass_msg command statement\n");
        passMsg(currentMsg);
        break;

    case UPDATE_ALIAS:
        //Update the user's alias to a new string
        printf("In Update_Alias\n");
        updateConnUserAlias(currentMsg);
        alertUsersNewUser(currentMsg);
        break;

    case OUTPUT_TOKEN_INFO:
        //This is a java side command - the DE2 will update all connected androids that a token has moved.
        printf("In Output_Token_Info\n");

        break;

    case DISCONNECT_DEV:
        //A device disconnected, so cleanup everything it owns and alert all other users that this player,
        //	and their tokens no longer exist
        printf("In DISCONNECT_DEV\n");

        if (dmID == currentMsg->androidID) {
            dmID = 0;
            sendAllUsersDMID(dmID);
        }

        alertUsersOfUserDC(currentMsg); // removes their alias
        removeTokensOfOneUser(currentMsg, REMOVEALLVAL); // removes all references to DC'd players tokens from all other users.
        removeTokenFromUser(currentMsg->androidID);
        clearUserInfo(currentMsg);
        alt_up_char_buffer_clear(char_buffer); // refresh buffer.
        break;

    case REMOVE_TOKEN:
        //Android removes token from DE2 - needs to be cleaned up
        //	Then others need to be notified of token removed from game
        printf("In Remove_Token");
        byteInfo = *(currentMsg->buffer); // first byte in buffer is Token_ID;
        removeTokensOfOneUser(currentMsg, byteInfo);
        removeToken(byteInfo);
        break;

    default:
        printf("Error, invalid command received on DE2!");
        break;
    }

    return 0;
}
//
// Killing a reader forcibly removes its Token, if any
//
void Reader::kill()
{
	if (mToken)
		removeToken();
	NodeCore::kill();
}