Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Phobeste posted:

Well you could also do assert(bitmask & (1<<cert_bp) or whatever. I thought that was the point, it's kind of an overly-verbose way to get the point across.

Yeah, we don't know if certMask is used again. It's definitely not the same as m_certMask, though.

Being overly verbose usually isn't considered to be "clever".

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Subjunctive posted:

Why would you do it differently for those two cases?

Generally I favour consistency, so this is certainly a reasonable position to take. It's just that it's easy to recognise small powers of two and harder to recognise larger ones. Since small powers of two are easily recognised, so the song and dance about obtaining the value 2 seen in the original code snippet seems excessive. The transition point between powers of two that are "small" and "big" would be subjective. (For example, I would be able to identify 8192 as a power of 2, but I wouldn't assume that another programmer would do so as well. It would take me a moment's thought to identify it more specifically as 2 to the power 13.)

quote:

Using a hex literal isn't any clearer, IMO, but it wouldn't be horrible and I wouldn't bounce something at code review for it if that was the pattern. But do you really know that 0x8000000 is bit 27 as easily? (Count those zeroes!)

It is clear that it is a power of two, however, and so the nature of the operation being carried out is clear. I agree that if you need to know at a glance which bit it is it's a bit of a hassle.

Zombywuf
Mar 29, 2008

The correct way to test a bit in C++ is obviously:
C++ code:
#include <type_traits>
#include <cassert>

template<class Integer>
bool is_bit_set(int offset, Integer value) {
  static_assert(std::is_integral<Integer>::value, "Can only test integral types");
  assert(offset >= 0);
  assert(offset < sizeof(Integer) * 8);

  return value & (1 << offset);
}

return0
Apr 11, 2007

Zombywuf posted:

The correct way to test a bit in C++ is obviously:
C++ code:
#include <type_traits>
#include <cassert>

template<class Integer>
bool is_bit_set(int offset, Integer value) {
  static_assert(std::is_integral<Integer>::value, "Can only test integral types");
  assert(offset >= 0);
  assert(offset < sizeof(Integer) * 8);

  return value & (1 << offset);
}

why not just use value??

OddObserver
Apr 3, 2009

Zombywuf posted:

The correct way to test a bit in C++ is obviously:
C++ code:
#include <type_traits>
#include <cassert>

template<class Integer>
bool is_bit_set(int offset, Integer value) {
  static_assert(std::is_integral<Integer>::value, "Can only test integral types");
  assert(offset >= 0);
  assert(offset < sizeof(Integer) * 8);

  return value & (1 << offset);
}

Is the 8 correct?

FamDav
Mar 29, 2008

OddObserver posted:

Is the 8 correct?

you'd want to use CHAR_BIT, obviously

MutantBlue
Jun 8, 2001

OddObserver posted:

Is the 8 correct?

you'd want to use std::numeric_limits<Integer>::digits, obviously

Coffee Mugshot
Jun 26, 2010

by Lowtax

Hammerite posted:

(For example, I would be able to identify 8192 as a power of 2, but I wouldn't assume that another programmer would do so as well. It would take me a moment's thought to identify it more specifically as 2 to the power 13.)

1 << 13 is a lot clearer than 8192, imo. Especially if that 13 is derived from variable or some other computation.

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

Voted Worst Mom posted:

1 << 13 is a lot clearer than 8192, imo.

Yeah, which is why you use 0x2000.
More seriously, I like the kernel macro BIT(n) which does the shift and makes the intent clear.

FamDav
Mar 29, 2008

MutantBlue posted:

you'd want to use std::numeric_limits<Integer>::digits, obviously

how could i forget digits. so shameful

Coffee Mugshot
Jun 26, 2010

by Lowtax
That int should be HOST_WIDE_INT, too.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Voted Worst Mom posted:

That int should be HOST_WIDE_INT, too.

No, it most definitely should not be unless you're writing code that's part of GCC.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
It isn't used anywhere else. It's a verification check to ensure that we got to this function with the proper value in m_certMask. Also, clIdx is used as an index into a list (of certificates) later. There is no relation between the bits that a cert might have set and its position in the list.

Obviously 1 << 8 is the idiomatic way to get 2^8 especially when testing bits, but this wasn't that case.

Jonah Hex
May 22, 2014
Saw this and shook my head. Can you spot the problem(s)?
code:
#define MILLISECONDS_PER_SECOND 1000
LARGE_INTEGER time, freq;
LONGLONG timestamp;
time = KeQueryPerformanceCounter(&freq);
timestamp = (time.QuadPart/freq.QuadPart)*MILLISECONDS_PER_SECOND;

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

Jonah Hex posted:

Saw this and shook my head. Can you spot the problem(s)?
code:
#define MILLISECONDS_PER_SECOND 1000
LARGE_INTEGER time, freq;
LONGLONG timestamp;
time = KeQueryPerformanceCounter(&freq);
timestamp = (time.QuadPart/freq.QuadPart)*MILLISECONDS_PER_SECOND;

Most critically, time / freq is done in an integer context, isn't it? - http://stackoverflow.com/questions/6517435/dividing-unsigned-long-long

Also, I can figure out how many milliseconds there are in a second without that define, but if you must.

And you should probably multiply before dividing if you're gonna do that.

ulmont fucked around with this message at 20:47 on May 27, 2014

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Jonah Hex posted:

Saw this and shook my head. Can you spot the problem(s)?
code:
#define MILLISECONDS_PER_SECOND 1000
LARGE_INTEGER time, freq;
LONGLONG timestamp;
time = KeQueryPerformanceCounter(&freq);
timestamp = (time.QuadPart/freq.QuadPart)*MILLISECONDS_PER_SECOND;

perfcounters measure in ticks, not milliseconds!!!!

e: actually reading the code, it looks like that's taken care of

Malcolm XML fucked around with this message at 21:50 on May 27, 2014

nielsm
Jun 1, 2009



Malcolm XML posted:

perfcounters measure in ticks, not milliseconds!!!!

freq is ticks per second.

Jonah Hex
May 22, 2014

ulmont posted:

Most critically, time / freq is done in an integer context, isn't it? - http://stackoverflow.com/questions/6517435/dividing-unsigned-long-long

That was the big one. The other issue is using a high resolution timer then truncating it to milliseconds.

tractor fanatic
Sep 9, 2005

Pillbug
The windows GetTickCount has a resolution of like 10 or 16 milliseconds so if you want a millisecond but not a microsecond that's not unreasonable.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Dessert Rose posted:

It isn't used anywhere else. It's a verification check to ensure that we got to this function with the proper value in m_certMask. Also, clIdx is used as an index into a list (of certificates) later. There is no relation between the bits that a cert might have set and its position in the list.

Obviously 1 << 8 is the idiomatic way to get 2^8 especially when testing bits, but this wasn't that case.

This makes it materially harder to defend the code in question, I'd say.

Deus Rex
Mar 5, 2005

http://codepad.org/7OSoeuZo

PHP code:
<?php

var_dump(NAN, NAN < NAN, NAN > NAN, NAN > 0.0, NAN < 0.0,
         NAN == NAN /* the only comparison that seems correct */);
echo "\n----\n\n";
var_dump(INF, INF < INF, INF > INF, INF == INF);
pre:
float(NAN)
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)

----

float(INF)
bool(true)
bool(true)
bool(false)
Why is NaN greater than and less than all floating point values in PHP? In every other language I can think of that I've tried this in, the opposite is true: there is no floating point value which NaN is less than or greater than, including itself. PHP's interpretation of IEEE-754 is bizarrely non-conformist, if not just wrong.

quote:

Four mutually exclusive relations are possible: less than, equal, greater than, and unordered. The last case arises when at least one operand is NaN. Every NaN shall compare unordered with everything, including itself.

The results of comparing Infinity with itself here seem even more just as problematic, because the less than and greater than relations should be mutually exclusive.

Deus Rex fucked around with this message at 08:13 on May 28, 2014

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Deus Rex posted:

http://codepad.org/7OSoeuZo

PHP code:
<?php

var_dump(NAN, NAN < NAN, NAN > NAN, NAN > 0.0, NAN < 0.0,
         NAN == NAN /* the only comparison that seems correct */);
echo "\n----\n\n";
var_dump(INF, INF < INF, INF > INF, INF == INF);
pre:
float(NAN)
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)

----

float(INF)
bool(true)
bool(true)
bool(false)
Why is NaN greater than and less than all floating point values in PHP? In every other language I can think of that I've tried this in, the opposite is true: there is no floating point value which NaN is less than or greater than, including itself. PHP's interpretation of IEEE-754 is bizarrely non-conformist, if not just wrong.


The results of comparing Infinity with itself here seem even more problematic, because the less than and greater than relations should be mutually exclusive.

This looks to be a fuckup that was fixed in PHP 5.4, [e: Nb. codepad.org has been mostly unmaintained for years and uses outdated versions of everything - PHP 5.2.5, Perl 5.8.0 which is 12 years old, etc] cf. http://3v4l.org/MP38b

Blotto Skorzany fucked around with this message at 03:04 on May 28, 2014

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Yeah, they fixed that, but they left in the DELIGHTFUL thing where 32-bit and 64-bit platforms promote int to float at different thresholds, so you get different math results if you're operating on values between 2^32 and 2^64.

QuarkJets
Sep 8, 2008

ulmont posted:

Most critically, time / freq is done in an integer context, isn't it? - http://stackoverflow.com/questions/6517435/dividing-unsigned-long-long

Also, I can figure out how many milliseconds there are in a second without that define, but if you must.

And you should probably multiply before dividing if you're gonna do that.

But what if the number of milliseconds in a second changes? Then you can set MILLISECONDS_PER_SECOND to whatever the new number of milliseconds per second has become. It's like eggs, first their good for you, then they're bad, then they're good again, who knows what those crazy scientists are going to say next?!

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

QuarkJets posted:

But what if the number of milliseconds in a second changes? Then you can set MILLISECONDS_PER_SECOND to whatever the new number of milliseconds per second has become. It's like eggs, first their good for you, then they're bad, then they're good again, who knows what those crazy scientists are going to say next?!

That would be an ABI change in the universe, in which case you file a bug report with your chosen notion of the creator, and notify your customers of the outage.

JawnV6
Jul 4, 2004

So hot ...

Edison was a dick posted:

That would be an ABI change in the universe, in which case you file a bug report with your chosen notion of the creator, and notify your customers of the outage.

emerge world

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

JawnV6 posted:

emerge world

topical for the coding horrors thread :v:

TheresaJayne
Jul 1, 2011
Well this is a fresh one, I am just getting into Minecraft Mod Development,

I was looking at both Forgemod and Bukkit until i came across this laughable situation

in 1.7.2 they are getting rid of item Ids or as they want to call them "Magic Numbers"
so there is currently a method to return the object you are looking at

Block block = livingEntity.getTargetBlock(null,10);

Now i am developing in 1.6.4 which should not be affected except that they have deprecated ALL methods in the API including the older versions and have no replacement methods to actually do anything.

Currently the 1.6.4 javadoc reads as follows

getTargetBlock

@Deprecated
Block getTargetBlock(HashSet<Byte> transparent,
int maxDistance)
Deprecated. Magic value
Gets the block that the living entity has targeted.
Parameters:
transparent - HashSet containing all transparent block IDs (set to null for only air)
maxDistance - this is the maximum distance to scan (may be limited by server by at least 100 blocks, no less)
Returns:
block that the living entity has targeted


When asking one of the devs on IRC his answer was, "someone else who hasn't read the javadocs"

and when i pasted the Deprecated message he just reiterated his commment. and claimed that wasn't the javadoc.

So currently in Bukkit ALL the useful methods that might use an ID have been deprecated with no replacement methods available, and no explanation why included in the javadoc either.

Marta Velasquez
Mar 9, 2013

Good thing I was feeling suicidal this morning...
Fallen Rib
Somehow, my team's bugfixes aren't making it to the QE team for verification. When a full clean and rebuild of the entire BSP only took a few seconds, I got suspicious.

nightly_build.sh:
code:
#!/bin/bash -x

svn update

make clean

# TODO: Increase number of jobs when nightly build VM gets more RAM
make -j32

REV=`svn info | grep Rev | head -n 1 | cut -d ' ' -f 2`

cp image.bin /output_folder/image_${REV}.bin

cd /output_folder
svn add image_${REV}.bin
svn ci -m "${REV}"

exit 0
Makefile:
code:
EXE := image.bin

all : ${EXE}

clean : all
	rm ${EXE}

distclean :
	touch ${EXE}
	make clean

${EXE} :
	./build.sh >/dev/null 2>/dev/null
build.sh:
code:
#!/bin/bash -x

cd sdk_root
make
cd ..
cp sdk_root/output.bin image.bin
The QE department gets the new image every day through svn update

EAT THE EGGS RICOLA
May 29, 2008

My boss at my new job is an awesome perl greybeard, but the job is a python project so everything he writes for it just looks so horribly wrong.

Alereon
Feb 6, 2004

Dehumanize yourself and face to Trumpshed
College Slice

EAT THE EGGS RICOLA posted:

My boss at my new job is an awesome perl greybeard, but the job is a python project so everything he writes for it just looks so horribly wrong.
Not really related and I've probably posted this before, but we found some old-rear end Perl code in production that needed to be updated, and the only person we could find that admitted to any Perl coding experience was a secretary. She now spends part of her time maintaining this old Perl code.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

I've written too much Perl to let it appear on my résumé.

Doctor w-rw-rw-
Jun 24, 2008

Subjunctive posted:

I've written too much Perl to let it appear on my résumé.

Just like me and Android. >_<

Hughlander
May 11, 2005

Doctor w-rw-rw- posted:

Just like me and Android. >_<

I'll get you to write objective c on android just you wait.

QuarkJets
Sep 8, 2008

Doctor w-rw-rw- posted:

Just like me and Android. >_<

Isn't that basically just Java?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

QuarkJets posted:

Isn't that basically just Java?

No, it's much worse.

kitten smoothie
Dec 29, 2001

QuarkJets posted:

Isn't that basically just Java?

I am pretty sure he's referring to the fact that there are so many peculiarities and pain points about Android which go beyond the language.

I like Android as a user. But as a developer, well, I am getting awful glad my boss is switching me back over to our iOS product team in a month.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

QuarkJets posted:

Isn't that basically just Java?

I adore your naivety. It makes me happy.

Chin Strap
Nov 24, 2002

I failed my TFLC Toxx, but I no longer need a double chin strap :buddy:
Pillbug
Apologies if this has been posted before. Link

quote:

The default setup allows an unauthenticated user to access
administrative functions such as backing up of key files within the CMS.
This is done by appending the following to a domain using the software
affected.

/backup.php?a=2&k=6f15afa1ac4edea0g145e884116334b7

Where "a" is the file number to back up and "k" is the MD5key used to
authenticate the administrator, however if "k" does not match the
correct key rather than disallowing the unauthenticated user to back up
the file the service will provide the user with the correct key. For
example:

Failure, wrong key. The right key is 5f17aca1ae2edea0f145e884116371a5

Using this new key in the url such as below:
/backup.php?a=2&k=5f17aca1ae2edea0f145e884116371a5

Will allow the user to perform the backup of files.

In addition to this the key is generated by the code:
$backupkey=MD5

Making it trivial to decrypt the key provided above to gain the
administrators password and gain further control over the site.

Adbot
ADBOT LOVES YOU

substitute
Aug 30, 2003

you for my mum
I'm guessing this isn't the best way to log JS errors in your app...

global/includes/app/error_log.php
php:
<?
$e = $_POST['e'];
error_log(print_r($e, true));
?>
Wow there's all kinds of fun stuff in this folder.

global/includes/app/statusbar.php
code:
<div class="statusbar left"><span class="msg">Loading...</span></div>

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply