std::string CommandEventHandler::pull(std::vector<std::string>& args) { if (args.size() < 1) return agentWarnInvalidNumArgs(1); std::string path(args[0]); PRUint64 start = args.size() < 2 ? 0 : PR_strtod(args[1].c_str(), NULL); PRUint64 size = args.size() < 3 ? 0 : PR_strtod(args[2].c_str(), NULL); mDataEventHandler = new PullFileEventHandler(mBufSocket, path, start, size); return ""; }
NS_INTERFACE_MAP_END /* Implementation */ static nsresult GetValueFromString(const nsAString &aValueAsString, bool aPercentagesAllowed, float *aValue) { NS_ConvertUTF16toUTF8 value(aValueAsString); const char *str = value.get(); if (NS_IsAsciiWhitespace(*str)) return NS_ERROR_DOM_SYNTAX_ERR; char *rest; *aValue = float(PR_strtod(str, &rest)); if (rest == str || !NS_finite(*aValue)) { return NS_ERROR_DOM_SYNTAX_ERR; } if (*rest == '%' && aPercentagesAllowed) { *aValue /= 100; ++rest; } if (*rest == '\0') { return NS_OK; } return NS_ERROR_DOM_SYNTAX_ERR; }
NS_IMETHODIMP nsSVGLength::SetValueAsString(const nsAString & aValueAsString) { nsresult rv = NS_OK; char *str = ToNewCString(aValueAsString); char* number = str; while (*number && isspace(*number)) ++number; if (*number) { char *rest; float value = float(PR_strtod(number, &rest)); if (rest!=number) { const char* unitStr = nsCRT::strtok(rest, "\x20\x9\xD\xA", &rest); PRUint16 unitType = SVG_LENGTHTYPE_UNKNOWN; if (!unitStr || *unitStr=='\0') { unitType = SVG_LENGTHTYPE_NUMBER; } else { nsCOMPtr<nsIAtom> unitAtom = do_GetAtom(unitStr); if (unitAtom == nsGkAtoms::px) unitType = SVG_LENGTHTYPE_PX; else if (unitAtom == nsGkAtoms::mm) unitType = SVG_LENGTHTYPE_MM; else if (unitAtom == nsGkAtoms::cm) unitType = SVG_LENGTHTYPE_CM; else if (unitAtom == nsGkAtoms::in) unitType = SVG_LENGTHTYPE_IN; else if (unitAtom == nsGkAtoms::pt) unitType = SVG_LENGTHTYPE_PT; else if (unitAtom == nsGkAtoms::pc) unitType = SVG_LENGTHTYPE_PC; else if (unitAtom == nsGkAtoms::em) unitType = SVG_LENGTHTYPE_EMS; else if (unitAtom == nsGkAtoms::ex) unitType = SVG_LENGTHTYPE_EXS; else if (unitAtom == nsGkAtoms::percentage) unitType = SVG_LENGTHTYPE_PERCENTAGE; } if (IsValidUnitType(unitType) && NS_FloatIsFinite(value)) { WillModify(); mValueInSpecifiedUnits = value; mSpecifiedUnitType = unitType; DidModify(); } else { // parse error // not a valid unit type rv = NS_ERROR_DOM_SYNTAX_ERR; } } else { // parse error // no number rv = NS_ERROR_DOM_SYNTAX_ERR; } } nsMemory::Free(str); return rv; }
nsresult SVGNumberList::SetValueFromString(const nsAString& aValue) { SVGNumberList temp; nsCharSeparatedTokenizerTemplate<IsSVGWhitespace> tokenizer(aValue, ',', nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL); nsAutoCString str; // outside loop to minimize memory churn while (tokenizer.hasMoreTokens()) { CopyUTF16toUTF8(tokenizer.nextToken(), str); // NS_ConvertUTF16toUTF8 const char *token = str.get(); if (*token == '\0') { return NS_ERROR_DOM_SYNTAX_ERR; // nothing between commas } char *end; float num = float(PR_strtod(token, &end)); if (*end != '\0' || !NS_finite(num)) { return NS_ERROR_DOM_SYNTAX_ERR; } if (!temp.AppendItem(num)) { return NS_ERROR_OUT_OF_MEMORY; } } if (tokenizer.lastTokenEndedWithSeparator()) { return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma } return CopyFrom(temp); }
double getDouble() { if (mState == eIllegal || mBuffer.IsEmpty() || (mBuffer.Length() == 1 && mBuffer[0] == '.')) { return MOZ_DOUBLE_NaN(); } return mSign*PR_strtod(mBuffer.get(), 0); }
std::string CommandEventHandler::push(std::vector<std::string>& args) { if (args.size() < 2) return agentWarnInvalidNumArgs(2); std::string path(args[0]); PRUint64 size = PR_strtod(args[1].c_str(), NULL); mDataEventHandler = new PushFileEventHandler(mBufSocket, path, size); return ""; }
nsresult nsSVGElement::ParseNumberOptionalNumber(const nsAString& aValue, PRUint32 aIndex1, PRUint32 aIndex2) { NS_ConvertUTF16toUTF8 value(aValue); const char *str = value.get(); if (NS_IsAsciiWhitespace(*str)) return NS_ERROR_FAILURE; char *rest; float x = float(PR_strtod(str, &rest)); float y = x; if (str == rest || !NS_FloatIsFinite(x)) { //first value was illformed return NS_ERROR_FAILURE; } if (*rest != '\0') { while (NS_IsAsciiWhitespace(*rest)) { ++rest; } if (*rest == ',') { ++rest; } y = float(PR_strtod(rest, &rest)); if (*rest != '\0' || !NS_FloatIsFinite(y)) { //second value was illformed or there was trailing content return NS_ERROR_FAILURE; } } NumberAttributesInfo numberInfo = GetNumberInfo(); numberInfo.mNumbers[aIndex1].SetBaseValue(x, this, PR_FALSE); numberInfo.mNumbers[aIndex2].SetBaseValue(y, this, PR_FALSE); return NS_OK; }
void PrefChanged(const char* aPref, void* aClosure) { if (strcmp(aPref, PREF_VOLUME_SCALE) == 0) { nsAdoptingString value = Preferences::GetString(aPref); StaticMutexAutoLock lock(sMutex); if (value.IsEmpty()) { sVolumeScale = 1.0; } else { NS_ConvertUTF16toUTF8 utf8(value); sVolumeScale = std::max<double>(0, PR_strtod(utf8.get(), nullptr)); } } else if (strcmp(aPref, PREF_CUBEB_LATENCY_PLAYBACK) == 0) { // Arbitrary default stream latency of 100ms. The higher this // value, the longer stream volume changes will take to become // audible. sCubebPlaybackLatencyPrefSet = Preferences::HasUserValue(aPref); uint32_t value = Preferences::GetUint(aPref, CUBEB_NORMAL_LATENCY_MS); StaticMutexAutoLock lock(sMutex); sCubebPlaybackLatencyInMilliseconds = std::min<uint32_t>(std::max<uint32_t>(value, 1), 1000); } else if (strcmp(aPref, PREF_CUBEB_LATENCY_MSG) == 0) { sCubebMSGLatencyPrefSet = Preferences::HasUserValue(aPref); uint32_t value = Preferences::GetUint(aPref, CUBEB_NORMAL_LATENCY_FRAMES); StaticMutexAutoLock lock(sMutex); // 128 is the block size for the Web Audio API, which limits how low the // latency can be here. // We don't want to limit the upper limit too much, so that people can // experiment. sCubebMSGLatencyInFrames = std::min<uint32_t>(std::max<uint32_t>(value, 128), 1e6); } else if (strcmp(aPref, PREF_CUBEB_LOG_LEVEL) == 0) { nsAdoptingString value = Preferences::GetString(aPref); NS_ConvertUTF16toUTF8 utf8(value); LogModule* cubebLog = LogModule::Get("cubeb"); if (strcmp(utf8.get(), "verbose") == 0) { cubeb_set_log_callback(CUBEB_LOG_VERBOSE, CubebLogCallback); cubebLog->SetLevel(LogLevel::Verbose); } else if (strcmp(utf8.get(), "normal") == 0) { cubeb_set_log_callback(CUBEB_LOG_NORMAL, CubebLogCallback); cubebLog->SetLevel(LogLevel::Error); } else if (utf8.IsEmpty()) { cubeb_set_log_callback(CUBEB_LOG_DISABLED, nullptr); cubebLog->SetLevel(LogLevel::Disabled); } } }
NS_INTERFACE_MAP_END //---------------------------------------------------------------------- // nsISVGValue methods: NS_IMETHODIMP nsSVGRect::SetValueString(const nsAString& aValue) { nsresult rv = NS_OK; char* str = ToNewCString(aValue); char* rest = str; char* token; const char* delimiters = ",\x20\x9\xD\xA"; double vals[4]; int i; for (i=0;i<4;++i) { if (!(token = nsCRT::strtok(rest, delimiters, &rest))) break; // parse error char *end; vals[i] = PR_strtod(token, &end); if (*end != '\0') break; // parse error } if (i!=4 || (nsCRT::strtok(rest, delimiters, &rest)!=0)) { // there was a parse error. rv = NS_ERROR_FAILURE; } else { WillModify(); mX = float(vals[0]); mY = float(vals[1]); mWidth = float(vals[2]); mHeight = float(vals[3]); DidModify(); } nsMemory::Free(str); return rv; }
static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv) { PLOptStatus os; PRIntn loops = 1; PRFloat64 answer; const char *number = "1234567890123456789"; PRFileDesc *err = PR_GetSpecialFD(PR_StandardError); PLOptState *opt = PL_CreateOptState(argc, argv, "hc:l:"); while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { if (PL_OPT_BAD == os) continue; switch (opt->option) { case 'n': /* number to translate */ number = opt->value; break; case 'l': /* number of times to run the tests */ loops = atoi(opt->value); break; case 'h': /* user wants some guidance */ Help(); /* so give him an earful */ return 2; /* but not a lot else */ break; default: break; } } PL_DestroyOptState(opt); PR_fprintf(err, "Settings\n"); PR_fprintf(err, "\tNumber to translate %s\n", number); PR_fprintf(err, "\tLoops to run test: %d\n", loops); while (loops--) { answer = PR_strtod(number, NULL); PR_fprintf(err, "Translation = %20.0f\n", answer); } return 2; }
static int PrefChanged(const char* aPref, void* aClosure) { if (strcmp(aPref, PREF_VOLUME_SCALE) == 0) { nsAdoptingString value = Preferences::GetString(aPref); MutexAutoLock lock(*gAudioPrefsLock); if (value.IsEmpty()) { gVolumeScale = 1.0; } else { NS_ConvertUTF16toUTF8 utf8(value); gVolumeScale = std::max<double>(0, PR_strtod(utf8.get(), nullptr)); } } else if (strcmp(aPref, PREF_CUBEB_LATENCY) == 0) { // Arbitrary default stream latency of 100ms. The higher this // value, the longer stream volume changes will take to become // audible. uint32_t value = Preferences::GetUint(aPref, 100); MutexAutoLock lock(*gAudioPrefsLock); gCubebLatency = std::min<uint32_t>(std::max<uint32_t>(value, 20), 1000); } return 0; }
void PrefChanged(const char* aPref, void* aClosure) { if (strcmp(aPref, PREF_VOLUME_SCALE) == 0) { nsAdoptingString value = Preferences::GetString(aPref); StaticMutexAutoLock lock(sMutex); if (value.IsEmpty()) { sVolumeScale = 1.0; } else { NS_ConvertUTF16toUTF8 utf8(value); sVolumeScale = std::max<double>(0, PR_strtod(utf8.get(), nullptr)); } } else if (strcmp(aPref, PREF_CUBEB_LATENCY) == 0) { // Arbitrary default stream latency of 100ms. The higher this // value, the longer stream volume changes will take to become // audible. sCubebLatencyPrefSet = Preferences::HasUserValue(aPref); uint32_t value = Preferences::GetUint(aPref, CUBEB_NORMAL_LATENCY_MS); StaticMutexAutoLock lock(sMutex); sCubebLatency = std::min<uint32_t>(std::max<uint32_t>(value, 1), 1000); } }
PRBool SVGLength::SetValueFromString(const nsAString &aValue) { float tmpValue; PRUint16 tmpUnit; NS_ConvertUTF16toUTF8 value(aValue); const char *str = value.get(); while (*str != '\0' && IsSVGWhitespace(*str)) { ++str; } char *unit; tmpValue = float(PR_strtod(str, &unit)); if (unit != str && NS_finite(tmpValue)) { char *theRest = unit; if (*unit != '\0' && !IsSVGWhitespace(*unit)) { while (*theRest != '\0' && !IsSVGWhitespace(*theRest)) { ++theRest; } nsCAutoString unitStr(unit, theRest - unit); tmpUnit = GetUnitTypeForString(unitStr.get()); if (tmpUnit == nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN) { // nsSVGUtils::ReportToConsole return PR_FALSE; } } else { tmpUnit = nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER; } while (*theRest && IsSVGWhitespace(*theRest)) { ++theRest; } if (!*theRest) { mValue = tmpValue; mUnit = tmpUnit; return PR_TRUE; } } return PR_FALSE; }
int32_t SVGAnimatedTransformList::SMILAnimatedTransformList::ParseParameterList( const nsAString& aSpec, float* aVars, int32_t aNVars) { NS_ConvertUTF16toUTF8 spec(aSpec); nsACString::const_iterator start, end; spec.BeginReading(start); spec.EndReading(end); SkipWsp(start, end); int numArgsFound = 0; while (start != end) { char const *arg = start.get(); char *argend; float f = float(PR_strtod(arg, &argend)); if (arg == argend || argend > end.get() || !NS_finite(f)) return -1; if (numArgsFound < aNVars) { aVars[numArgsFound] = f; } start.advance(argend - arg); numArgsFound++; SkipWsp(start, end); if (*start == ',') { ++start; SkipWsp(start, end); } } return numArgsFound; }
NS_IMETHODIMP nsAbIPCCard::Copy(nsIAbCard *srcCard) { NS_ENSURE_ARG_POINTER(srcCard); nsresult rv; nsCOMPtr<nsIAbMDBCard> dbCard; dbCard = do_QueryInterface(srcCard, &rv); if(NS_SUCCEEDED(rv) && dbCard) { nsXPIDLString palmIDStr; nsresult rv = dbCard->GetStringAttribute(CARD_ATTRIB_PALMID, getter_Copies(palmIDStr)); if(NS_SUCCEEDED(rv) && palmIDStr.get()) { PRFloat64 f = PR_strtod(NS_LossyConvertUCS2toASCII(palmIDStr).get(), nsnull); PRInt64 l; LL_D2L(l, f); LL_L2UI(mRecordId, l); } else mRecordId = 0; // set tableID, RowID and Key for the card PRUint32 tableID=0; dbCard->GetDbTableID(&tableID); SetDbTableID(tableID); PRUint32 rowID=0; dbCard->GetDbRowID(&rowID); SetDbRowID(rowID); PRUint32 key; dbCard->GetKey(&key); SetKey(key); } PRUint32 lastModifiedDate = 0; srcCard->GetLastModifiedDate(&lastModifiedDate); mStatus = (lastModifiedDate) ? ATTR_MODIFIED : ATTR_NEW; rv = nsAbCardProperty::Copy(srcCard); // do we need to join the work and home addresses? // or split them? return rv; }
PRBool nsAbIPCCard::Same(nsIAbCard *card) { if(!card) return PR_FALSE; nsresult rv; nsCOMPtr<nsIAbMDBCard> dbCard; dbCard = do_QueryInterface(card, &rv); if(NS_SUCCEEDED(rv)) { // first check the palmID for the cards if they exist nsXPIDLString palmIDStr; rv = dbCard->GetStringAttribute(CARD_ATTRIB_PALMID, getter_Copies(palmIDStr)); if(NS_SUCCEEDED(rv) && palmIDStr.get()) { PRInt32 palmID=0; PRFloat64 f = PR_strtod(NS_LossyConvertUCS2toASCII(palmIDStr).get(), nsnull); PRInt64 l; LL_D2L(l, f); LL_L2UI(palmID, l); if(palmID && mRecordId) return mRecordId == palmID; } } nsXPIDLString str; card->GetFirstName(getter_Copies(str)); if (Compare(str, m_FirstName, nsCaseInsensitiveStringComparator())) return PR_FALSE; card->GetLastName(getter_Copies(str)); if (Compare(str, m_LastName, nsCaseInsensitiveStringComparator())) return PR_FALSE; card->GetDisplayName(getter_Copies(str)); if (Compare(str, m_DisplayName, nsCaseInsensitiveStringComparator())) return PR_FALSE; card->GetNickName(getter_Copies(str)); if (Compare(str, m_NickName, nsCaseInsensitiveStringComparator())) return PR_FALSE; return PR_TRUE; }
double nsCString::ToDouble(PRInt32* aErrorCode) const { double res = 0.0; if (mLength > 0) { char *conv_stopped; const char *str = mData; // Use PR_strtod, not strtod, since we don't want locale involved. res = PR_strtod(str, &conv_stopped); if (conv_stopped == str+mLength) *aErrorCode = (PRInt32) NS_OK; else // Not all the string was scanned *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; } else { // The string was too short (0 characters) *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; } return res; }
static nsresult GetValueFromString(const nsAString &aValueAsString, float *aValue, PRUint16 *aUnitType) { NS_ConvertUTF16toUTF8 value(aValueAsString); const char *str = value.get(); if (NS_IsAsciiWhitespace(*str)) return NS_ERROR_DOM_SYNTAX_ERR; char *rest; *aValue = float(PR_strtod(str, &rest)); if (rest != str && NS_FloatIsFinite(*aValue)) { *aUnitType = GetUnitTypeForString(rest); if (IsValidUnitType(*aUnitType)) { return NS_OK; } } return NS_ERROR_DOM_SYNTAX_ERR; }
inline double nsSMILParserUtils::GetFloat(nsACString::const_iterator& aIter, const nsACString::const_iterator& aIterEnd, nsresult *aErrorCode) { char *end; const char *start = aIter.get(); double value = PR_strtod(start, &end); nsresult rv = NS_OK; if (end == start || end > aIterEnd.get()) { rv = NS_ERROR_FAILURE; } else { aIter.advance(end - start); } if (aErrorCode) { *aErrorCode = rv; } return value; }
bool SVGLength::SetValueFromString(const nsAString &aValue) { float tmpValue; uint16_t tmpUnit; NS_ConvertUTF16toUTF8 value(aValue); const char *str = value.get(); while (*str != '\0' && IsSVGWhitespace(*str)) { ++str; } char *unit; tmpValue = float(PR_strtod(str, &unit)); if (unit != str && NS_finite(tmpValue)) { char *theRest = unit; while (*theRest != '\0' && !IsSVGWhitespace(*theRest)) { ++theRest; } tmpUnit = GetUnitTypeForString( Substring(aValue, unit - str, theRest - unit)); if (tmpUnit == nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN) { // SVGContentUtils::ReportToConsole return false; } while (*theRest && IsSVGWhitespace(*theRest)) { ++theRest; } if (!*theRest) { mValue = tmpValue; mUnit = tmpUnit; return true; } } return false; }
NS_INTERFACE_MAP_END /* Implementation */ nsresult nsSVGNumber2::SetBaseValueString(const nsAString &aValueAsString, nsSVGElement *aSVGElement, PRBool aDoSetAttr) { NS_ConvertUTF16toUTF8 value(aValueAsString); const char *str = value.get(); if (NS_IsAsciiWhitespace(*str)) return NS_ERROR_FAILURE; char *rest; float val = float(PR_strtod(str, &rest)); if (rest == str || *rest != '\0') { return NS_ERROR_FAILURE; } mBaseVal = mAnimVal = val; return NS_OK; }
NS_IMETHODIMP nsSVGNumber::SetValueString(const nsAString& aValue) { nsresult rv = NS_OK; WillModify(); char *str = ToNewCString(aValue); if (*str) { char *rest; double value = PR_strtod(str, &rest); if (rest && rest!=str) { if (*rest=='%') { rv = SetValue(float(value/100.0)); rest++; } else { rv = SetValue(float(value)); } // skip trailing spaces while (*rest && isspace(*rest)) ++rest; // check to see if there is trailing stuff... if (*rest != '\0') { rv = NS_ERROR_FAILURE; NS_ERROR("trailing data in number value"); } } else { rv = NS_ERROR_FAILURE; // no number } } nsMemory::Free(str); DidModify(); return rv; }
$NetBSD$ --- mozilla/content/media/nsAudioStream.cpp.orig 2012-11-19 22:42:14.000000000 +0000 +++ mozilla/content/media/nsAudioStream.cpp @@ -298,7 +298,11 @@ static int PrefChanged(const char* aPref gVolumeScale = NS_MAX<double>(0, PR_strtod(utf8.get(), nullptr)); } } else if (strcmp(aPref, PREF_USE_CUBEB) == 0) { +#if defined(__FreeBSD__) && __FreeBSD_version < 800097 + bool value = Preferences::GetBool(aPref, false); +#else bool value = Preferences::GetBool(aPref, true); +#endif mozilla::MutexAutoLock lock(*gAudioPrefsLock); gUseCubeb = value; } else if (strcmp(aPref, PREF_CUBEB_LATENCY) == 0) {
Window XRemoteClient::FindBestWindow(const char *aProgram, const char *aUsername, const char *aProfile) { Window root = RootWindowOfScreen(DefaultScreenOfDisplay(mDisplay)); Window bestWindow = 0; Window root2, parent, *kids; unsigned int nkids; // Get a list of the children of the root window, walk the list // looking for the best window that fits the criteria. if (!XQueryTree(mDisplay, root, &root2, &parent, &kids, &nkids)) { PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("XQueryTree failed in XRemoteClient::FindBestWindow")); return 0; } if (!(kids && nkids)) { PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("root window has no children")); return 0; } // We'll walk the list of windows looking for a window that best // fits the criteria here. for (unsigned int i = 0; i < nkids; i++) { Atom type; int format; unsigned long nitems, bytesafter; unsigned char *data_return = 0; Window w; w = kids[i]; // find the inner window with WM_STATE on it w = CheckWindow(w); int status = XGetWindowProperty(mDisplay, w, mMozVersionAtom, 0, (65536 / sizeof (long)), False, XA_STRING, &type, &format, &nitems, &bytesafter, &data_return); if (!data_return) continue; double version = PR_strtod((char*) data_return, nullptr); XFree(data_return); if (!(version >= 5.1 && version < 6)) continue; data_return = 0; if (status != Success || type == None) continue; // If someone passed in a program name, check it against this one // unless it's "any" in which case, we don't care. If someone did // pass in a program name and this window doesn't support that // protocol, we don't include it in our list. if (aProgram && strcmp(aProgram, "any")) { status = XGetWindowProperty(mDisplay, w, mMozProgramAtom, 0, (65536 / sizeof(long)), False, XA_STRING, &type, &format, &nitems, &bytesafter, &data_return); // If the return name is not the same as what someone passed in, // we don't want this window. if (data_return) { if (strcmp(aProgram, (const char *)data_return)) { XFree(data_return); continue; } // This is actually the success condition. XFree(data_return); } else { // Doesn't support the protocol, even though the user // requested it. So we're not going to use this window. continue; } } // Check to see if it has the user atom on that window. If there // is then we need to make sure that it matches what we have. const char *username; if (aUsername) { username = aUsername; } else { username = PR_GetEnv("LOGNAME"); } if (username) { status = XGetWindowProperty(mDisplay, w, mMozUserAtom, 0, (65536 / sizeof(long)), False, XA_STRING, &type, &format, &nitems, &bytesafter, &data_return); // if there's a username compare it with what we have if (data_return) { // If the IDs aren't equal, we don't want this window. if (strcmp(username, (const char *)data_return)) { XFree(data_return); continue; } XFree(data_return); } } // Check to see if there's a profile name on this window. If // there is, then we need to make sure it matches what someone // passed in. if (aProfile) { status = XGetWindowProperty(mDisplay, w, mMozProfileAtom, 0, (65536 / sizeof(long)), False, XA_STRING, &type, &format, &nitems, &bytesafter, &data_return); // If there's a profile compare it with what we have if (data_return) { // If the profiles aren't equal, we don't want this window. if (strcmp(aProfile, (const char *)data_return)) { XFree(data_return); continue; } XFree(data_return); } } // Check to see if the window supports the new command-line passing // protocol, if that is requested. // If we got this far, this is the best window. It passed // all the tests. bestWindow = w; break; } if (kids) XFree((char *) kids); return bestWindow; }
int main(int argc, char **argv) #endif { double num; double num1; double zero = 0.0; char cnvt[50]; char *thousands; num = 1e24; num1 = PR_strtod("1e24",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","1e24"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("1e+24",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = 0.001e7; num1 = PR_strtod("0.001e7",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","0.001e7"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("10000",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = 0.0000000000000753; num1 = PR_strtod("0.0000000000000753",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n", "0.0000000000000753"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("7.53e-14",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = 1.867e73; num1 = PR_strtod("1.867e73",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","1.867e73"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("1.867e+73",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = -1.867e73; num1 = PR_strtod("-1.867e73",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e73"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("-1.867e+73",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = -1.867e-73; num1 = PR_strtod("-1.867e-73",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e-73"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("-1.867e-73",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } /* Testing for infinity */ num = 1.0 / zero; num1 = PR_strtod("1.867e765",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","1.867e765"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("Infinity",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = -1.0 / zero; num1 = PR_strtod("-1.867e765",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e765"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("-Infinity",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } /* Testing for NaN. PR_strtod can't parse "NaN" and "Infinity" */ num = zero / zero; PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("NaN",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = - zero / zero; PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("NaN",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = 1.0000000001e21; num1 = PR_strtod("1.0000000001e21",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n", "1.0000000001e21"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("1.0000000001e+21",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = -1.0000000001e-21; num1 = PR_strtod("-1.0000000001e-21",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n", "-1.0000000001e-21"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("-1.0000000001e-21",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } /* * Bug 414772: should not exit with "Zero passed to d2b" in debug * build. */ num1 = PR_strtod("4e-356",NULL); /* * A very long input with ~384K digits. * Bug 516396: Should not crash. * Bug 521306: Should return 0 without converting the input. */ #define LENGTH (384 * 1024) thousands = (char *)malloc(LENGTH); thousands[0] = '0'; thousands[1] = '.'; memset(&thousands[2], '1', LENGTH - 3); thousands[LENGTH - 1] = '\0'; num = 0; num1 = PR_strtod(thousands,NULL); free(thousands); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n", "0.1111111111111111..."); failed_already = 1; } if (failed_already) { printf("FAILED\n"); } else { printf("PASSED\n"); } return failed_already; }
int main( int argc, char* argv[] ) { double num; double num1; double zero = 0.0; char cnvt[50]; num = 1e24; num1 = PR_strtod("1e24",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","1e24"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("1e+24",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = 0.001e7; num1 = PR_strtod("0.001e7",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","0.001e7"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("10000",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = 0.0000000000000753; num1 = PR_strtod("0.0000000000000753",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n", "0.0000000000000753"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("7.53e-14",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = 1.867e73; num1 = PR_strtod("1.867e73",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","1.867e73"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("1.867e+73",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = -1.867e73; num1 = PR_strtod("-1.867e73",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e73"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("-1.867e+73",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = -1.867e-73; num1 = PR_strtod("-1.867e-73",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e-73"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("-1.867e-73",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } /* Testing for infinity */ num = 1.0 / zero; num1 = PR_strtod("1.867e765",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","1.867e765"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("Infinity",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = -1.0 / zero; num1 = PR_strtod("-1.867e765",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e765"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("-Infinity",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } /* Testing for NaN. PR_strtod can't parse "NaN" and "Infinity" */ num = zero / zero; PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("NaN",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = - zero / zero; PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("NaN",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = 1.0000000001e21; num1 = PR_strtod("1.0000000001e21",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n", "1.0000000001e21"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("1.0000000001e+21",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } num = -1.0000000001e-21; num1 = PR_strtod("-1.0000000001e-21",NULL); if(num1 != num){ fprintf(stderr,"Failed to convert numeric value %s\n", "-1.0000000001e-21"); failed_already = 1; } PR_cnvtf(cnvt,sizeof(cnvt),20,num); if(strcmp("-1.0000000001e-21",cnvt) != 0){ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt); failed_already = 1; } if (failed_already) { printf("FAILED\n"); } else { printf("PASSED\n"); } return failed_already; }
nsresult SVGPointList::SetValueFromString(const nsAString& aValue) { // The spec says that the list is parsed and accepted up to the first error // encountered, so we must call CopyFrom even if an error occurs. We still // want to throw any error code from setAttribute if there's a problem // though, so we must take care to return any error code. nsresult rv = NS_OK; SVGPointList temp; nsCharSeparatedTokenizerTemplate<IsSVGWhitespace> tokenizer(aValue, ',', nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL); nsAutoCString str1, str2; // outside loop to minimize memory churn while (tokenizer.hasMoreTokens()) { CopyUTF16toUTF8(tokenizer.nextToken(), str1); const char *token1 = str1.get(); if (*token1 == '\0') { rv = NS_ERROR_DOM_SYNTAX_ERR; break; } char *end; float x = float(PR_strtod(token1, &end)); if (end == token1 || !NS_finite(x)) { rv = NS_ERROR_DOM_SYNTAX_ERR; break; } const char *token2; if (*end == '-') { // It's possible for the token to be 10-30 which has // no separator but needs to be parsed as 10, -30 token2 = end; } else { if (!tokenizer.hasMoreTokens()) { rv = NS_ERROR_DOM_SYNTAX_ERR; break; } CopyUTF16toUTF8(tokenizer.nextToken(), str2); token2 = str2.get(); if (*token2 == '\0') { rv = NS_ERROR_DOM_SYNTAX_ERR; break; } } float y = float(PR_strtod(token2, &end)); if (*end != '\0' || !NS_finite(y)) { rv = NS_ERROR_DOM_SYNTAX_ERR; break; } temp.AppendItem(SVGPoint(x, y)); } if (tokenizer.lastTokenEndedWithSeparator()) { rv = NS_ERROR_DOM_SYNTAX_ERR; // trailing comma } nsresult rv2 = CopyFrom(temp); if (NS_FAILED(rv2)) { return rv2; // prioritize OOM error code over syntax errors } return rv; }